//压缩整个目录下载

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. 安全运维之:Linux系统账户和登录安全(转)

    三.删减系统登录欢迎信息 系统的一些欢迎信息或版本信息,虽然能给系统管理者带来一定的方便,但是这些信息有时候可能被黑客利用,成为攻击服务器的帮凶,为了保证系统的安全,可以修改或删除某些系统文件,需要修 ...

  2. 在cocos2d-x界面中嵌入Android的WebView

    在Cocos2dxActivity.java中, (1) 增加函数onCreateLayout, [java]  view plain copy   public LinearLayout onCre ...

  3. lastcomm搜索并显示以前执行过的命令信息

    lastcomm搜索并显示以前执行过的命令信息

  4. linux下so动态库一些不为人知的秘密(中)

    上一篇(linux下so动态库一些不为人知的秘密(上))介绍了linux下so一些依赖问题,本篇将介绍linux的so路径搜索问题. 我们知道linux链接so有两种途径:显示和隐式.所谓显示就是程序 ...

  5. asp.net基础学习笔记

    原文地址:http://blog.csdn.net/oxoxzhu/article/details/8652530 1.概论 浏览器-服务器 B/S 浏览的      浏览器和服务器之间的交互,形成上 ...

  6. linux脚本之简单实例

    利用脚本计算10的阶乘 简单说明一下: #!/bin/bash说明该shell使用的bash shell程序.这一句不可少for i in `seq 1 10`还可以写成for i in 1 2 3 ...

  7. MarkDown基础使用教程-by sixleaves

    以下是个人浏览文档,结合自己平时使用所总结, 和引用国外关于如何使用markdown的教程.如有不足,还请海涵,期待于您的交流.我觉得使用markdown书写挺好的! 工具下载,可以去下载gitboo ...

  8. 【LeetCode练习题】Candy

    分糖果 There are N children standing in a line. Each child is assigned a rating value. You are giving c ...

  9. 把DEDE的在线文本编辑器换成Kindeditor不显示问题

    在织梦论坛下载了[Kindeditor编辑器For DedeCMS],按照操作说明安装后,后台文章编辑的区域却显示空白,有人说不兼容V57版本,有人说不兼容gbk版本,我也纠结了很久,在网上找了很多版 ...

  10. 网络工程 POST与GET请求方法的本质区别

    POST与GET请求方法的本质区别: 第一:GET用于信息获取,它是安全的(这里安全的含义是指非修改信息),而POST是用于修改服务器上资源的请求 第二:GET请求的数据会附在URL之后,而POST把 ...