当前位置: 代码迷 >> 综合 >> IE浏览器下载文本文件(txt,csv等)
  详细解决方案

IE浏览器下载文本文件(txt,csv等)

热度:65   发布时间:2024-02-10 22:56:10.0

后端

private void DownloadMaterialTemp(HttpContext context){string FileCompath = System.Web.HttpContext.Current.Server.MapPath("~") + "Files/物料基础信息导入模板.csv";using (FileStream fs = new FileStream(FileCompath, FileMode.Open)){byte[] buffer = new byte[fs.Length];fs.Read(buffer, 0, (int)fs.Length);string encodefileName = System.Web.HttpUtility.UrlEncode("物料基础信息导入模板.csv", System.Text.Encoding.UTF8);context.Response.Headers["Content-Disposition"] = "attachment;filename="+ encodefileName;//输出文件格式context.Response.ContentType = "text/csv; charset=\"utf-8\"";//防止乱码context.Response.OutputStream.Write(buffer, 0, buffer.Length);context.Response.End();}}

前端

window.open(MaterialMgtUrl + "?action=downloadTemp");