Content type for file handler

  • Thread starter Thread starter SushiSean
  • Start date Start date
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?
 
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,
 
Back
Top