[浏览器]IE下载中文文件名乱码问题

在使用IE下载包含中文文件的时候,会出现乱码(在Chrome下没有此问题),解决方法是使用UrlEncode,如下

public static void DownloadExcel(HSSFWorkbook book, String fileNamePre)
        {
            var stream = new MemoryStream();
            book.Write(stream);
            stream.Flush();
            stream.Position = 0;

            string fileName = HttpUtility.UrlEncode(string.Format("{1}_{0:yyyy-MM-dd_HH_mm}.xls", System.DateTime.Now, fileNamePre));
            HttpResponse response = HttpContext.Current.Response;
            response.ContentType = "application/vnd.ms-excel";
            response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", fileName));
            response.Clear();
            response.BinaryWrite(stream.GetBuffer());
            response.End();
        }


你可能感兴趣的:(浏览器)