Mime type

J

Johan Pingree

What class is available to me to "discover" the mime type of a file that I
want to stream?
I must be having a brain fart today as I cannot find anything that does
this.

Thanks for your pointers.
 
P

Patrice

Humm. I don't know if it exists in the FCL but keep in mind that you won't
have necessarily this information server side.

My personal preference would be rather to have this as part of my data (as a
table perhaps) rather than to have to do some server configuration to
declare this...

Patrice
 
J

Johan Pingree

Well IMHO this should be possible. If I have a file on the system locally,
lets say it is an excel file. I should be able to get a mime mapping/content
type that would equal: application/vnd.ms-excel OR if it is a bitmap file I
should be able to get: image/x-bitmap

This is, I discovered, possible, but by no means efficient, see:
System.Net.FileWebResponse.ContentType
It is like going in through the out door!

I guess I will have to manage this in my own mapping table for now.
Hopefully some at Microsoft will pick up on this and address it.
 
P

Patrice

If you really want you could use interop to read mime types.

Keep in mind that you are server side. If Excel is not installed you won't
know its mimetype. Do you want to install each and every application just to
be able to download its files ?
Another option would be then to write just the appropriate info to the
registry and finally it's easier to keep your own table.

What would be great would be rather to use a web service and keep the
ability to supplant a particular mimetype if needed (sometimes the mimetype
may also not be the one you want).

Hope it clarifies a bit whay I'm reluctant to get this info from the system.

Patrice


--
 
J

Johan Pingree

Yes, I will ponder creating a soap service and for now I will use a database
table to map them.
To give you an brief on why I want this: I am developing a web based dotNet
webmail application. Recieved email often has attachments. I want to stream
those attachement to the user when they request an attached file. I would
like to be able to set the response content-type of the file going to the
end user.

I do appreciate you taking the time to answer - thank you.

Johan.
 
K

Kevin Spencer

There are a limited number of MIME Types, in the few hundreds, I believe. If
you want to get the MIME type for a file, you can do it by extension. Just
do a little research on MIME types, figure out what file extensions you are
going to be using, and create a table to hold the file extensions and their
associated MIME types. Then refer to that table when you need to. That's
pretty much how IIS does it, and pretty much how browsers do it.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top