In ASP.net, when you write a file stream simply in response, you may be misread by the browser, such as a picture or. htm, which will appear directly when the browser is opened. But the demand is, pop-up saved panel prompts the user to save.
So, here are a few steps that are essential.
Copy Code code as follows:
Response.Clear ();
Response.AddHeader ("Content-disposition", "attachment; Filename= "+ clientname);
Response.ContentType = "Application/octet-stream";
Response.WriteFile (filename);//response.transmitfile (filename);
The objectives are:
Empty the response already content (because you are most likely to be used in aspx.cs, or if you do not know, HttpResponse already have some content)
Modify Httpheader,
modifying MIME types
Write to file stream
The last line, using either WriteFile or TransmitFile, can be, but slightly different, better at using transmitfile efficiency, because it "writes the specified file directly to the HTTP response output stream without buffering the file in memory."
And here's mime and httpheader for all types of file downloads.