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

主要是要判斷瀏覽器是否是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