ASP. NET implements garbled processing of downloaded Chinese file names
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
A few days ago, we added the file management download function to the system, which must be implemented in the aspx file for permission control, so we added the followingCode:
Response. contenttype = mime; // the corresponding MIME type
Response. appendheader ("content-disposition", "attachment; filename = \" "+ filename + "\"");
Response. binarywrite (bytes );
Response. End ();
When filename contains Chinese characters, when the file is downloaded and saved, the file name becomes garbled and needs to be modified by the user, which violates the original intention of setting the preset file name.
Solution 1: perform URL encoding on filename and change the underlined sentence to response. appendheader ("content-disposition", "attachment; filename = \" "+ server. urlencode (filename) +.
Although the Chinese Garbled text problem has been solved, there is another problem: During the test, the downloaded and saved file names sometimes become the name of the page (. aspx), although the content can be downloaded locally, but you need to change the file name and type, this will bring a lot of confusion to the user.
There is another way to easily solve the above two problems:
Solution 2: assume that the current URL is http: // localhost/download. aspx? Id = 123, filename is "Download objects", we just need to change the download URL to http: // localhost/download. aspx/download objects? Id = 123. The underlined code can be commented out. Try it and you will be very satisfied with the result!
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
and provide relevant evidence. A staff member will contact you within 5 working days.