解决导出中文文件名乱码的方法

 792人阅读 评论(0) 收藏 举报
                fileName = HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
            return fileName;

        }public enum ExportType {WORD,EXCELL }

        public static void Export(string htmlToExport, string filename,ExportType eType)
        {
           
            filename = HttpUtility.UrlDecode(filename);
            string attachment = string.Empty;
            if (eType.ToString() == "WORD")
            {
                 attachment = "attachment;filename=" + GetToExcelName(filename) + ".doc";
                 System.Web.HttpContext.Current.Response.ContentType = "application/vnd.msword";
            }
            else
            {
                 attachment = "attachment;filename=" + GetToExcelName(filename) + ".doc";
                 System.Web.HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
            }
            System.Web.HttpContext.Current.Response.ClearContent();
            System.Web.HttpContext.Current.Response.AddHeader("content-disposition", attachment);
            System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
            //page.Response.ContentEncoding = page.Response.HeaderEncoding;
            

            System.Web.HttpContext.Current.Response.Write(htmlToExport);


            System.Web.HttpContext.Current.Response.End();
        }

相关文章:

  • 2021-05-16
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-16
  • 2022-12-23
  • 2021-12-07
  • 2022-12-23
猜你喜欢
  • 2021-08-17
  • 2021-07-06
  • 2021-05-26
  • 2021-11-30
  • 2022-12-23
  • 2021-08-26
  • 2021-10-19
相关资源
相似解决方案