Content type for file handler

S

SushiSean

Hello. I have simple file handler.

public void ProcessRequest (HttpContext context)
{
context.Response.WriteFile(FullRealPath);
}

it works but not correct. if I am tring WriteFile some zip or mp3 in browser
open it as a text! As I know I need send correct ContentType. Something like
this
context.Response.ContentType = "image/jpeg";

but how I can found this param for any file? it can be image, text, zip, mp3
anthing.... Exist any way get content type basical on exist file?
 
M

Mohamad Elarabi

I think the easiest way is to set it to "Application/XXX" where XXX is the
actual extension of the file you're sending. For example "Application/PDF". I
think this causes the browser to just download the file and then Windows will
figure out what application to use to run this kind of extension.

This is managed on the client from
Windows Explorer/Tools/Folder Options/File Types

Let me know if that works. Thanks,
 

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

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top