zl程序教程

您现在的位置是:首页 >  后端

当前栏目

c# - 文件流下载-自定义工具

2023-09-14 09:06:39 时间
  //需要文件字节流、带后缀的文件名,mine类型
public static void exportFile(byte[] data, string fileName, string mine) { HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); HttpContext.Current.Response.ContentType = mine; HttpContext.Current.Response.BinaryWrite(data); HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); }