//压缩整个目录下载

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

ICSharpCode.SharpZipLib.Zip的更多相关文章

  1. 使用NPOI读取Excel报错ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature

    写了一个小程序利用NPOI来读取Excel,弹出这样的报错: ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature ...

  2. C#调用 ICSharpCode.SharpZipLib.Zip 实现解压缩功能公用类

    最近想用个解压缩功能 从网上找了找 加自己修改,个人感觉还是比较好用的,直接上代码如下 using System; using System.Linq; using System.IO; using ...

  3. 利用ICSharpCode.SharpZipLib.Zip进行文件压缩

    官网http://www.icsharpcode.net/ 支持文件和字符压缩. 创建全新的压缩包 第一步,创建压缩包 using ICSharpCode.SharpZipLib.Zip; ZipOu ...

  4. 使用ICSharpCode.SharpZipLib.Zip实现压缩与解压缩

    使用开源类库ICSharpCode.SharpZipLib.Zip可以实现压缩与解压缩功能,源代码和DLL可以从http://www.icsharpcode.net/OpenSource/SharpZ ...

  5. 基于ICSharpCode.SharpZipLib.Zip的压缩解压缩

    原文:基于ICSharpCode.SharpZipLib.Zip的压缩解压缩 今天记压缩解压缩的使用,是基于开源项目ICSharpCode.SharpZipLib.Zip的使用. 一.压缩: /// ...

  6. c# ICSharpCode.SharpZipLib.Zip实现文件的压缩

    首先了解ZipOutPutStream和ZipEntry对象 ZipOutPutStream对象 如果要完成一个文件或文件夹的压缩,则要使用ZipOutputStream类.ZipOutputStre ...

  7. C# ICSharpCode.SharpZipLib.Zip 的使用

    public static class ZipFileHelper { #region 加压解压方法 /// <summary> /// 功能:压缩文件(暂时只压缩文件夹下一级目录中的文件 ...

  8. ICSharpCode.SharpZipLib.Zip 压缩文件

    public class ZipFileHelper { List<string> urls = new List<string>(); void Director(strin ...

  9. 使用ICSharpCode.SharpZipLib.Zip类库解压zip文件的方法

    public static bool ZipExtractFile(string zipFilePath,string targetPath) { FastZip fastZip = new Fast ...

随机推荐

  1. iOS 开发者必知的 75 个工具

    你可以从软件开发者如何使用工具中看出他水准如何.有经验的开发者精于使用工具.对你目前所使用的工具不断研究,同时了解一些替代品的使用,当你目前所用的工具无法满足你的需要时可以填补空缺. 记住了这些,我将 ...

  2. json概述及python处理json等数据类型

    <一,概念> 序列化(Serialization):将对象的状态信息转换为可以存储或可以通过网络传输的过程,传输的格式可以是JSON.XML等.反序列化(deserialization): ...

  3. ALLEN-XIE

    ALLEN-XIE ABOUT   Allen Xie是一家坚持理念至上的西装定制店.我们的价值观渗透于我们所做的每一件事中,从而确保始终遵循自己的风格.我们坚持用最高标准要求自己,因此,在制衣过程中 ...

  4. #include <boost/scoped_array.hpp>

    多个元素使用#include <boost/scoped_array.hpp> 单个元素使用#include <boost/scoped_ptr.hpp> 作用域数组 作用域数 ...

  5. Java中的import

    有些人写了一阵子 Java,可是对于 Java的 package 跟 import 还是不太了解.很多人以为原始码 .java 文件中的 import 会让编译器把所 import 的程序通通写到编译 ...

  6. Apache启用GZIP压缩网页传输方法

    一.gzip介绍 Gzip是一种流行的文件压缩算法,如今的应用十分广泛,尤其是在Linux平台.当应用Gzip压缩到一个纯文本文件时,效果是很明显的,大约能够降低70%以上的文件大小.这取决于文件里的 ...

  7. swift Dictionary 字典

    // //  main.swift //  字典 // //  Created by zhangbiao on 14-6-15. //  Copyright (c) 2014年 理想. All rig ...

  8. 代码混淆 GSON完满解决

    头疼的问题,json使用了google的gson三方包,可是混淆的时候出了问题 明明已经按照gson的官方文档,把混淆脚本加上去了,却还是出问题. 今天同事找到一篇博客,关于这个问题的: 我们是将js ...

  9. 《think in python》学习-9

    think in python think in python -9 案例分析:文字游戏 从文本文件中读取文字 作者提供了一个文本文件words.txt 地址 本章后面案例也会用带该文件中的词组 fi ...

  10. C#读取csv格式文件

    方法1:用一个System.Web.UI.HtmlControls.HtmlInputFile去handle文件选取 以下是button click event中的code,用来执行当文件选取了之后读 ...