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 );
}