c#导出文件,文件名中文乱码解决方法。

时间:2021-09-24 06:32:53
 1 public string clFielName(string fileName)
 2     {
 3         System.Web.HttpContext curContext = System.Web.HttpContext.Current;
 4         string outputFileName = null;
 5         string browser = curContext.Request.UserAgent.ToUpper();
 6         if (browser.Contains("MS") == true && browser.Contains("IE") == true)
 7         {
 8             outputFileName = System.Web.HttpUtility.UrlEncode(fileName);
 9         }
10         else if (browser.Contains("FIREFOX") == true)
11         {
12             outputFileName = "\"" + fileName + "\"";
13         }
14         else
15         {
16             outputFileName = System.Web.HttpUtility.UrlEncode(fileName);
17         }
18         return outputFileName;
19     }