C# IE、Chrome、Firefox下載方法判斷 - 解決下載檔名亂碼問題
主要是要判斷瀏覽器是否是IE,如果是IE,檔名需要先使用Urlencode編碼,如果是Chrome或Firefox則不需要,用這種方式才可避免下載的檔名變亂碼!#region 判斷瀏覽器版本
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpBrowserCapabilities brObject = HttpContext.Current.Request.Browser;
string Tourversion = brObject.Type;
if (Tourversion == "IE11" || Tourversion == "IE10" || Tourversion == "IE9" || Tourversion == "IE8" || Tourversion == "IE7" || Tourversion == "IE6" || Tourversion == "InternetExplorer11")
{
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode("" + mobanName + "" + "." + format, System.Text.Encoding.UTF8));
}
else if (Tourversion.Contains("Chrome") || Tourversion.Contains("Firefox"))
{
string fileName = mobanName + "." + format;
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
}
#endregion
Reference:
IE、Chrome、Firefox下載方法判斷(C#)
http://hi.baidu.com/vebujoqnffbbord/item/fd534d302210eb1ecfb9fe38
頁:
[1]