我們一般下載中文檔名一般會utf-8編碼再下載,火狐瀏覽器會出現檔名亂碼,解決辦法,火狐瀏覽器檔名不編碼,直接下載:
HttpContext curContext = HttpContext.Current; // 設定編碼和附件格式 curContext.Response.ContentType = "application/vnd.ms-excel"; curContext.Response.ContentEncoding = Encoding.UTF8; curContext.Response.Charset = ""; strFileName = strFileName + DateTime.Now.ToString("yyyyMMddHHmmss"); string userAgent = curContext.Request.ServerVariables["http_user_agent"].ToLower(); if (userAgent.IndexOf("firefox", StringComparison.Ordinal) == -1) { strFileName = HttpUtility.UrlEncode(strFileName, Encoding.UTF8) + ".xls"; } curContext.Response.AppendHeader("Content-Disposition", "attachment;filename=" + strFileName); curContext.Response.BinaryWrite(ListToExcel(list, strFileName, titleDic).GetBuffer()); curContext.Response.End();