473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

get file type

In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath(sCurrentDir))

for each f in fld.subfolders
f.type
next

How do you get a file type in .Net?
Nov 22 '05 #1
4 2105
Assuming you mean the extension of a file you can use the fileinfo class

http://msdn.microsoft.com/library/de...ClassTopic.asp

It has a method GetExtension

http://msdn.microsoft.com/library/de...nsiontopic.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath(sCurrentDir))

for each f in fld.subfolders
f.type
next

How do you get a file type in .Net?

Nov 22 '05 #2
Use the FileInfo.Extension property.

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath(sCurrentDir))

for each f in fld.subfolders
f.type
next

How do you get a file type in .Net?
Nov 22 '05 #3
I'm don't think you understand the code I posted. f.type doesn't return the
file extension. f.type returns the type of file that it is. For example:

ASP File
ASPX File
HTML Document
JScript Script File
Text Document

For a better look...put this code into an ASP file in a virtural directory
that has some other files in it and look at the output.

<%
dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath("."))
for each f in fld.files
response.write f.type
response.write "<br>"
next
%>

"John Timney ( MVP )" wrote:
Assuming you mean the extension of a file you can use the fileinfo class

http://msdn.microsoft.com/library/de...ClassTopic.asp

It has a method GetExtension

http://msdn.microsoft.com/library/de...nsiontopic.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath(sCurrentDir))

for each f in fld.subfolders
f.type
next

How do you get a file type in .Net?


Nov 22 '05 #4
Ohh, ok. Here is one way to get it:
http://pinvoke.net/default.aspx/shell32.SHGetFileInfo

Basically, you P/Invoke SHGetFileInfo() shell API.

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:FB**********************************@microsof t.com...
I'm don't think you understand the code I posted. f.type doesn't return the
file extension. f.type returns the type of file that it is. For example:

ASP File
ASPX File
HTML Document
JScript Script File
Text Document

For a better look...put this code into an ASP file in a virtural directory
that has some other files in it and look at the output.

<%
dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath("."))
for each f in fld.files
response.write f.type
response.write "<br>"
next
%>

"John Timney ( MVP )" wrote:
Assuming you mean the extension of a file you can use the fileinfo class

http://msdn.microsoft.com/library/de...ClassTopic.asp

It has a method GetExtension

http://msdn.microsoft.com/library/de...nsiontopic.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"CLEAR-RCIC" <CL*******@discussions.microsoft.com> wrote in message
news:2A**********************************@microsof t.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createobject("Scripting.FileSystemObject")
set fld = fs.GetFolder(server.mappath(sCurrentDir))

for each f in fld.subfolders
f.type
next

How do you get a file type in .Net?


Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
5
by: Dave Smithz | last post by:
Hi There, I have a PHP script that sends an email with attachment and works great when provided the path to the file to send. However this file needs to be on the same server as the script. ...
4
by: M P | last post by:
Can you help me find an asp code that will upload a file from my PC to web server? Mark
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
15
by: Nathan | last post by:
I have an aspx page with a data grid, some textboxes, and an update button. This page also has one html input element with type=file (not inside the data grid and runat=server). The update...
3
by: Shapper | last post by:
Hello, I created a script to upload a file. To determine the file type I am using userPostedFile.ContentType. For example, for a png image I get "image/png". My questions are: 1. Where can...
11
by: mesut demir | last post by:
Hi All, When I create fields (in files) I need assign a data type like char, varchar, money etc. I have some questions about the data types when you create fields in a file. What is the...
4
by: Jim Michaels | last post by:
after a file upload, $_FILES is not populated but $_POST is. what's going on here? $_POST=C $_POST=C $_POST=C $_POST=C:\\www\\jimm\\images\\bg1.jpg $_FILES= $_FILES= $_FILES=
0
by: rautsmita | last post by:
hello friends , i am using to jdk6 and JAXB2.0, i have geomtry.xsd file i am trying to compile this file using jaxb but i got some error i.e.The particle of the type is not a valid restriction of...
1
by: shyaminf | last post by:
hi everybody! iam facing a problem with the transfer of file using servlet programming. i have a code for uploading a file. but i'm unable to execute it using tomcat5.5 server. kindly help me how to...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.