views:

269

answers:

1

I've written a httphandler to process downloading of files. Regardless of the mime-type, all files try default to notepad when using Firefox. My Code snippet is below.

//let's assume that the item object has these values.
item.Filename = "testfile.pdf";
item.MimeType = "application/pdf";

context.Response.Buffer = true;
context.Response.Clear();
context.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", item.Filename));
context.Response.ContentType = item.MimeType;
byte[] rawData = item.Data.ToArray();
context.Response.OutputStream.Write(rawData, 0, rawData.Length);
context.Response.End();

It works properly in IE and Chrome.