Reputation: 143
I am trying to download a file (includes pdf, zip, images, etc) in C#. I have tried the code in the following link.
http://www.daniweb.com/web-development/aspnet/threads/252778
http://dotnetslackers.com/Community/blogs/haissam/archive/2007/04/03/Downloading-Files-C_2300_.aspx
It's working as expected in IE. But in Firefox the downloaded zip and image file is corrupted.
Upvotes: 1
Views: 1257
Reputation: 3678
The problem may be with the FILENAME parameter in the Content-Disposition header.
You can try the sample code by following these rules:
Content-Type header should refer to an unknown MIME type
FileInfo fi = new FileInfo(@"c:\picture.bmp");
Response.Clear();
Response.ContentType = "application/x-unknown";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", System.Web.HttpUtility.UrlPathEncode(fi.Name)));
Response.AddHeader("Content-Length", fi.Length.ToString());
Response.TransmitFile(fi.FullName);
Response.End();
Upvotes: 1