473,569 Members | 2,789 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get file type

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

dim fs, fld, f
set fs = server.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.mappath(sC urrentDir))

for each f in fld.subfolders
f.type
next

How do you get a file type in .Net?
Nov 22 '05 #1
4 2122
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*******@disc ussions.microso ft.com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.mappath(sC urrentDir))

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.Extens ion property.

"CLEAR-RCIC" <CL*******@disc ussions.microso ft.com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.mappath(sC urrentDir))

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.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.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*******@disc ussions.microso ft.com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.mappath(sC urrentDir))

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*******@disc ussions.microso ft.com> wrote in message
news:FB******** *************** ***********@mic rosoft.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.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.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*******@disc ussions.microso ft.com> wrote in message
news:2A******** *************** ***********@mic rosoft.com...
In the old days, you could get a file type in ASP by doing:

dim fs, fld, f
set fs = server.createob ject("Scripting .FileSystemObje ct")
set fld = fs.GetFolder(se rver.mappath(sC urrentDir))

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
3911
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in...
5
5439
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. I want to develop a webpage where people can send attachments that are stored on their local PC.
4
2182
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
3921
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. It is almost like it is trying to implement it's own COM interfaces... below is the header, and a link to the dll+code: Zip file with header,...
15
4733
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 button will verify the information that has been entered and updates the data base if the data is correct. Update will throw an exception if the data is...
3
3155
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 I find a list of all the types which can be returned? For example, if it is a Word document will it return "document/doc".
11
3419
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 difference between data type 'CHAR' and 'TEXT'? When do you use 'VAR' in your datatype word? e.g. VARCHAR ?
4
5886
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
2619
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 the particle of the base this xsd file is valid as per w3c standard i am also providing error in detail and geometry.xsd file geometry.xsd <?xml...
1
5577
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 execute it using tomcat server5.5. the code is as follows. if you have any other coding regarding this, please send me.it's urgent. import...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7672
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1212
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.