ASP.NET c#文件的下载

2021-04-26 03:26

阅读:565

标签:enc   stream   cat   文件   pos   保存   文件的   c#   system   

  //WriteFile实现下载
  protected void Button2_Click(object sender, EventArgs e)
  {
 

  string fileName="aaa.zip";//客户端保存的文件名
  string filePath=Server.MapPath("DownLoad/aaa.zip");//路径

  FileInfo fileInfo=new FileInfo(filePath);
  Response.Clear();
  Response.ClearContent();
  Response.ClearHeaders();
  Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
  Response.AddHeader("Content-Length", fileInfo.Length.ToString());
  Response.AddHeader("Content-Transfer-Encoding", "binary");
  Response.ContentType="application/octet-stream";
  Response.ContentEncoding=System.Text.Encoding.GetEncoding("gb2312");
  Response.WriteFile(fileInfo.FullName);
  Response.Flush();
  Response.End();
  }

ASP.NET c#文件的下载

标签:enc   stream   cat   文件   pos   保存   文件的   c#   system   

原文地址:http://www.cnblogs.com/ZXiaoHu-html/p/7904176.html


评论


亲,登录后才可以留言!