zoukankan      html  css  js  c++  java
  • 利用DotNetZip服务端压缩文件并下载

    public void DownFile() {
                  string filePath = Server.MapPath("/Files/txt/bb.txt");//文件所在位置
                  var fs = Response.OutputStream;
                using(Ionic.Zip.ZipFile zf = new Ionic.Zip.ZipFile())

        {
                  zf.AddFile(filePath, "txtfile");
                  //zf.Save(Server.MapPath("/Files/")+"dd.zip");//文件保存的地址
                  zf.Save(fs);//保存到输出流

        }

                string fileName = "dd.zip"; //下载显示的文件名字
                //string filePath = Server.MapPath("/Files/txt/bb.txt");
                //FileStream fs = new FileStream(filePath, FileMode.Open);
                //byte[] bytes = new byte[fs.Length];
                //fs.Read(bytes, 0, bytes.Length);
                //fs.Close();

                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                //Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }

    类库下载地址:http://dotnetzip.codeplex.com/

  • 相关阅读:
    【php数组函数序列】之array_values()
    Mysql数据库编码问题3(修改数据库,表,字段编码为utf8)
    framework fckedit / KingEditor
    Linux + JDK/TOMCAT/Dia(Planner)/eclipse
    proxyServer squid / varnish / apache traffic server / ATS
    framework SiteMesh
    Linux + BusyBox
    对链表的插入操作
    链表原理
    链表的删除操作
  • 原文地址:https://www.cnblogs.com/si-shaohua/p/3838096.html
Copyright © 2011-2022 走看看