wei325
 try
        {
            string excelName = Request["excelName"].ToString(); //文件路径
            string fileName = Request["fileName"].ToString(); //下载的文件名
            if(!(string.IsNullOrEmpty(excelName)|| string.IsNullOrEmpty(fileName)))
            {
                Response.Charset = "GB2312";
                Response.ContentEncoding = Encoding.GetEncoding("GB2312");
                Response.ContentType="application/vnd.ms-excel";
                //火狐浏览器不需将中文文件名进行编码格式转换
                if (Request.ServerVariables["http_user_agent"].ToLower().IndexOf("firefox") == -1)
                {
                    excelName = HttpUtility.UrlEncode(excelName, System.Text.Encoding.UTF8);
                }
                Response.AppendHeader("Content-Disposition", "attachment;filename=" +excelName);
                Response.WriteFile(fileName);
                Response.Flush();
                Response.Close();
            }
        }
        catch
        { }

 注意判断浏览器 IE需要将中文文件名编码格式转换,而firefox浏览器则不用,不然下载下来的中文文件名会乱码

分类:

技术点:

相关文章:

  • 2021-11-24
  • 2021-12-27
  • 2021-12-27
  • 2021-12-27
  • 2021-12-17
  • 2022-02-01
  • 2021-08-26
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
  • 2021-12-27
相关资源
相似解决方案