In asp.net, you can simply write a file stream in response, which can be read by the browser by mistake. For example, an image or a .htm will be displayed directly when it is opened by the browser. However, the pop-up save panel prompts you to save.
The following steps are required.
CopyCodeThe Code is as follows: Response. Clear ();
Response. addheader ("content-disposition", "attachment; filename =" + clientname );
Response. contenttype = "application/octet-stream ";
Response. writefile (filename); // response. transmitfile (filename );
The purpose is:
Clear the existing content in the response (because you may be using it in Aspx. CS, or some content in httpresponse without your knowledge)
Modify httpheader,
Modify MIME type
Write File stream
The last line can be writefile or transmitfile, but it is slightly different. It is more efficient to use transmitfile because it "writes the specified file directly to the HTTP Response output stream, instead of caching the file in the memory ".
Here, mime and httpheader are suitable for downloading all types of files.