我们一般下载中文文件名一般会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();