473,326 Members | 2,255 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,326 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 2102
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.