http://liuzhicheng2005.blog.163.com/blog/static/81808084201022964221977/ 

(2)建立下载文件的方法,所有文件以流的形式来下载

public void DownLoadFile(string fileName)

    {

    //清除缓冲区中的所有HTML输出

    Response.Clear();

    Response.Buffer=true;

    //设置输出流的HTTP字符集

    Response.Charset="utf-8";

    //attachment参数表示作为附件下载

    string attachment = "attachment; filename=" +

HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);

    Response.AddHeader("content-disposition",

attachment);

   

   

    //设置输出流的HttpMIMe类型(以流形式输出)

    Response.ContentType="application/octent-stream";

    //

    Response.WriteFile(fileName);

    Response.End();

    }

//好处就是可以判断一个文件的下载,下载任何格式的文件

相关文章:

  • 2021-12-05
  • 2021-09-02
  • 2021-05-19
  • 2021-07-14
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2021-06-24
  • 2022-12-23
  • 2021-11-04
  • 2021-09-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案