找回密碼
 註冊
搜索
查看: 7845|回復: 0

C# IE、Chrome、Firefox下載方法判斷 - 解決下載檔名亂碼問題

[複製鏈接]
發表於 2014-11-3 15:12:34 | 顯示全部樓層 |閱讀模式
主要是要判斷瀏覽器是否是IE,如果是IE,檔名需要先使用Urlencode編碼,如果是Chrome或Firefox則不需要,用這種方式才可避免下載的檔名變亂碼!
  1. #region 判斷瀏覽器版本
  2. HttpContext.Current.Response.ContentType = "application/octet-stream";
  3. HttpBrowserCapabilities brObject = HttpContext.Current.Request.Browser;
  4. string Tourversion = brObject.Type;
  5. if (Tourversion == "IE11" || Tourversion == "IE10" || Tourversion == "IE9" || Tourversion == "IE8" || Tourversion == "IE7" || Tourversion == "IE6" || Tourversion == "InternetExplorer11")
  6. {
  7.    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("" + mobanName + "" + "." + format, System.Text.Encoding.UTF8));
  8. }
  9. else if (Tourversion.Contains("Chrome") || Tourversion.Contains("Firefox"))
  10. {
  11.   string fileName = mobanName + "." + format;
  12.   HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
  13. }
  14. #endregion
複製代碼

Reference:
IE、Chrome、Firefox下載方法判斷(C#)
http://hi.baidu.com/vebujoqnffbbord/item/fd534d302210eb1ecfb9fe38
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

Archiver|手機版|彩色筆小沛的知識庫

GMT+8, 2024-11-21 18:22 , Processed in 0.018808 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回復 返回頂部 返回列表