ASP.NET

IE下載中文檔名出現亂碼
  • 1# JDP
  • 625102014-6-27 11:12:03
當瀏覽器是IE時,利用UrlPathEncode編碼來解決亂碼問題
  1. protected void btnDownload_Click(object sender, EventArgs e)
  2. {
  3.     string str = "測 試.doc";
  4.     if (context.Request.Browser.Browser == "IE")
  5.         str = HttpUtility.UrlPathEncode(str);
  6.     else
  7.         str = string.Format(""{0}"", str);
  8.     Context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", str));            
  9. }
複製代碼

Reference:
ASP.NET 如何設定強制下載檔案並正確處理中文檔名的問題
http://blog.miniasp.com/post/200 ... name-correctly.aspx
UrlPathEncode 用於檔案下載出現亂碼的問題
http://paladinprogram.blogspot.tw/2012/07/urlpathencode.html
倒序瀏覽 看全部 全部回復
暫無回復,快來搶沙發
回復 收藏 轉播 分享 淘帖