Solution to the garbled Chinese file name of Response in FireFox/IE

Source: Internet
Author: User

I found that many people in the garden are using this method when processing the Response download file name.
Response. AppendHeader ("Content-Disposition", "attachment; filename =" + HttpUtility. UrlEncode (fileInfo. Name, System. Text. Encoding. UTF8 ));
However, this is only applicable to scenarios without spaces or IE.

If you want to output an unencoded file in FireFox and the space in the file name output in IE is not a + sign, you need to judge it once more.
Copy codeThe Code is as follows:
If (Request. UserAgent. ToLower (). IndexOf ("msie")>-1)
{
Downloadfilename = HttpUtility. UrlPathEncode (downloadfilename );
}
If (Request. UserAgent. ToLower (). IndexOf ("firefox")>-1)
{
Response. AddHeader ("Content-Disposition", "attachment; filename = \" "+ downloadfilename + "\"");
}
Else
{
Response. AddHeader ("Content-Disposition", "attachment; filename =" + downloadfilename );
}

Contact Us

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: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.