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("没有下载的数据!");
    }

  • 相关阅读:
    ISC2016训练赛 phrackCTF--Classical CrackMe
    JCTF 2014 小菜一碟
    攻防世界--ReverseMe-120
    lstm torch
    pandas 处理 纽约签到数据集
    python datatime
    tf.keras 模型 多个输入 tf.data.Dataset
    python **kwarg和*args
    java 优先队列 大根堆
    python总结
  • 原文地址:https://www.cnblogs.com/fx2008/p/3209893.html
Copyright © 2011-2022 走看看