get file type

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
Use the FileInfo.Extension property.

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?
 
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
%>
 
Ohh, ok. Here is one way to get it:
http://pinvoke.net/default.aspx/shell32.SHGetFileInfo

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

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
%>
 
Back
Top