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

  • 相关阅读:
    Android中各级目录的作用
    轻量级java开发(一)-Hibernate 安装
    Eclipse 安装插件
    Eclipse超级完美汉化教程
    JAVA中extends 与implements区别
    Java基础语法总结
    C#笔试题面试题锦集(全)总20篇
    Nginx集群
    Redis 集群方案
    MS Sql Server 中主从库的配置和使用介绍
  • 原文地址:https://www.cnblogs.com/fx2008/p/3209893.html
Copyright © 2011-2022 走看看