• 利用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/

  • 相关阅读:
    前端知识之HTML内容
    数据库之表操作
    初识数据库
    Python连接MySQL数据库之pymysql模块使用
    并发编程之协程
    个人库
    Apache conf配置文件 allow deny order files directory location解释,re(正则表达式)入门速成
    Arduino在vscode中输出乱码解决方案及解释
    UOJ Judgement Failed惨痛教训
    vscode导出插件列表
  • 原文地址:https://www.cnblogs.com/si-shaohua/p/3838096.html
Copyright © 2020-2023  润新知