后端
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");