zoukankan      html  css  js  c++  java
  • ICSharpCode.SharpZipLib.Zip

    //压缩整个目录下载

    var projectFolder = Request.Params["folder"] != null ? Request.Params["folder"] : string.Empty;
    if (!string.IsNullOrWhiteSpace(projectFolder))
    {
    string path = Util.GetMapPath(string.Format("attarch/html/{0}", projectFolder));
    Response.Clear();
    Response.ContentType = "application/zip";
    Response.AddHeader("Content-Disposition", string.Format("attachment; filename="{0}.zip"", projectFolder));
    Response.BufferOutput = false;

    var buffer = new byte[1024 * 1024];
    using (var zipOutputStream = new ZipOutputStream(Response.OutputStream, 1024 * 1024))
    {
    zipOutputStream.SetLevel(0);
    var directoryInfo = new DirectoryInfo(path);
    foreach (string file in Directory.GetFiles(directoryInfo.FullName, "*.*", SearchOption.AllDirectories))
    {
    string folder = Path.GetDirectoryName(file);
    if (folder.Length > directoryInfo.FullName.Length)
    {
    folder = folder.Substring(directoryInfo.FullName.Length).Trim('\') + @"";
    }
    else
    {
    folder = string.Empty;
    }
    zipOutputStream.PutNextEntry(new ZipEntry(folder + Path.GetFileName(file)));
    using (var fs = System.IO.File.OpenRead(file))
    {
    ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(fs, zipOutputStream, buffer);
    }
    zipOutputStream.Flush();
    Response.Flush();
    }
    zipOutputStream.Finish();
    }
    Response.Flush();
    }
    else
    {
    HandlerMessage("没有下载的数据!");
    }

  • 相关阅读:
    Vue 环境配置
    Vue-think脚手架
    搭建vue环境网站
    数组 还是 字符串
    javascript jquery console调试方法说明
    获取 stoken 或者id MVC写法
    它山之石
    Android学习笔记_44_apk安装、反编译及防治反编译
    (转)超级实用且不花哨的js代码大全
    Android学习笔记_43_网络通信之文件断点上传
  • 原文地址:https://www.cnblogs.com/fx2008/p/3209893.html
Copyright © 2011-2022 走看看