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,
Add the following code:
...
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
Response. AppendHeader ("Content-Disposition", "attachment; filename =" "+ Server. UrlEncode (fileName) + """);
You can.
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!