Response. contenttype = "application/X-msdownload; charset = UTF-8 ";
First, encoding
Response. contentencoding = system. Text. encoding. utf8;
Then use the filename
System. Web. httputility. urlencode (name)
Then save the aspx file for response output in UTF-8 format
Finally, set in webconfig
<Globalization requestencoding = "UTF-8" responseencoding = "UTF-8"/>
One solution is ,:
After httputility urlencode, replace "+" with "% 20" (if it is "+", it is converted to "% 2B"), for example:
Filename = httputility. urlencode (filename, encoding. utf8 );
Filename = filename. Replace ("+", "% 20 ");
I don't understand why Microsoft converts spaces to plus signs instead of "% 20". Remember that JDK urlencoder converts spaces to "% 20.
After checking, the same is true in. net2.0.
========================================================== ======================================
String filename = ".xls ";
String filepath = @ "/upload/reports"
Fileinfo file = new fileinfo (system. Web. httpcontext. Current. server. mappath (filepath) + filename );
Response. charset = "UTF-8 ";
Response. contentencoding = system. Text. encoding. utf8;
// Add the header information and specify the default file name for the "download/Save as" dialog box
Response. addheader ("content-disposition", "attachment; filename =" + httputility. urlencode ("download file" + ". xls ", system. text. encoding. utf8 ));
// Add header information and specify the file size so that the browser can display the download progress.
Response. addheader ("Content-Length", file. length. tostring ());
// Specify a stream that cannot be read by the client and must be downloaded.
Response. contenttype = "application/MS-excel ";
// Send the file stream to the client
Response. writefile (file. fullname );
// Stop page execution
Response. End ();