Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Files Types

Reply
Thread Tools

Files Types

 
 
shapper
Guest
Posts: n/a
 
      10-19-2007
Hello,

I am uploading files to a server and I need to validate the extension
of its file and get the type from it.

For example:

..doc > Microsoft Word Document

..pdf > Adobe ...

Is there a way to do this?

And if not, where can I find a list of all extensions and names given
in Windows.

Thanks,

Miguel

 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      10-19-2007
There is no absolutely reliable way to do this. The OS stores some file
associations. Internet Explorer stores some. IIS stores some. Your best bet
is to get a list of MIME types from the web and create your own data store
of them. This can be as simple as a flat file, or stored in a database.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP

"shapper" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
> Hello,
>
> I am uploading files to a server and I need to validate the extension
> of its file and get the type from it.
>
> For example:
>
> .doc > Microsoft Word Document
>
> .pdf > Adobe ...
>
> Is there a way to do this?
>
> And if not, where can I find a list of all extensions and names given
> in Windows.
>
> Thanks,
>
> Miguel
>



 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      10-19-2007
"shapper" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...

> Is there a way to do this?


Following on from Kevin's reply, the following might be of some use to
you...

Supposing you have the following HTML control:
<input type="file" id="MyUpload" runat="server" />

you can add the accept tag which, depending on your browser, *might*
constrain the file patterns prompted for to match those with the
corresponding appropriate file extensions for the platform:
http://www.cs.tut.fi/~jkorpela/forms/file.html

E.g. <input type="file" id="MyUpload" runat="server"
accept="application/msword,application/pdf" />

Then, server-side, you can do the following:

// validate the file extention
if(Path.GetExtension(MyUpload.PostedFile.FileName) != ".doc" &&
Path.GetExtension(MyUpload.PostedFile.FileName) != ".pdf")
{
// do something here
}
// validate the MIME type
if(MyUpload.PostedFile.ContentType != "application/msword" &&
MyUpload.PostedFile.ContentType != "application/pdf")
{
// do something here
}

The <asp:FileUpload> webcontrol renders an HTML <input type="file"> control.

However, as Kevin states, this is not 100% reliable...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
Where are ref types that are members of value types stored? Sathyaish ASP .Net 2 05-22-2005 07:32 PM
missing types in module types? Manlio Perillo Python 0 05-29-2004 06:33 AM
Boost + Python C/API: Mixing python return types with boost return types Steve Knight Python 2 10-10-2003 10:11 AM
STD types vs C++ intrinsic types Jeremy Cowles C++ 5 08-19-2003 05:33 PM



Advertisments