Under FireFox and IE Response Chinese file name garble problem solution

  • 2020-05-24 05:31:12
  • OfStack

It has been found that many people in the garden are using this method when processing the Response file name download
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8));
But this is only for use without whitespace and IE.

If you want to output an unencoded file under FireFox, and if the space in the file name under IE is not +, you will have to make one more judgment.
 
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); 
} 

Related articles: