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("没有下载的数据!");
}
ICSharpCode.SharpZipLib.Zip的更多相关文章
- 使用NPOI读取Excel报错ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature
写了一个小程序利用NPOI来读取Excel,弹出这样的报错: ICSharpCode.SharpZipLib.Zip.ZipException:Wrong Local header signature ...
- C#调用 ICSharpCode.SharpZipLib.Zip 实现解压缩功能公用类
最近想用个解压缩功能 从网上找了找 加自己修改,个人感觉还是比较好用的,直接上代码如下 using System; using System.Linq; using System.IO; using ...
- 利用ICSharpCode.SharpZipLib.Zip进行文件压缩
官网http://www.icsharpcode.net/ 支持文件和字符压缩. 创建全新的压缩包 第一步,创建压缩包 using ICSharpCode.SharpZipLib.Zip; ZipOu ...
- 使用ICSharpCode.SharpZipLib.Zip实现压缩与解压缩
使用开源类库ICSharpCode.SharpZipLib.Zip可以实现压缩与解压缩功能,源代码和DLL可以从http://www.icsharpcode.net/OpenSource/SharpZ ...
- 基于ICSharpCode.SharpZipLib.Zip的压缩解压缩
原文:基于ICSharpCode.SharpZipLib.Zip的压缩解压缩 今天记压缩解压缩的使用,是基于开源项目ICSharpCode.SharpZipLib.Zip的使用. 一.压缩: /// ...
- c# ICSharpCode.SharpZipLib.Zip实现文件的压缩
首先了解ZipOutPutStream和ZipEntry对象 ZipOutPutStream对象 如果要完成一个文件或文件夹的压缩,则要使用ZipOutputStream类.ZipOutputStre ...
- C# ICSharpCode.SharpZipLib.Zip 的使用
public static class ZipFileHelper { #region 加压解压方法 /// <summary> /// 功能:压缩文件(暂时只压缩文件夹下一级目录中的文件 ...
- ICSharpCode.SharpZipLib.Zip 压缩文件
public class ZipFileHelper { List<string> urls = new List<string>(); void Director(strin ...
- 使用ICSharpCode.SharpZipLib.Zip类库解压zip文件的方法
public static bool ZipExtractFile(string zipFilePath,string targetPath) { FastZip fastZip = new Fast ...
随机推荐
- Python中metaclass解释
Classes as objects 首先,在认识metaclass之前,你需要认识下python中的class.python中class的奇怪特性借鉴了smalltalk语言.大多数语言中,clas ...
- 4.1. 如何在Windows环境下开发Python
4.1. 如何在Windows环境下开发Python 4.1. 如何在Windows环境下开发Python 4.1.1. Python的最原始的开发方式是什么样的 4.1.1.1. 找个文本编辑器,新 ...
- Unix/Linux环境C编程入门教程(24) MySQL 5.7.4 for Red Hat Enterprise 7(RHEL7)的安装
远观历史, MySQL的主要目的是为了能够在单处理器核心的商业服务器上运行.如今MySQL的一个变化用户可能不会注意到,那就是甲骨文已经开始重新架构MySQL的代码,使它大量的模块化.如软件解析器,优 ...
- hdu 5093 Battle ships 匈牙利 很巧妙的建图思路
//这题逼我把匈牙利学了 之前一直很勤快敲网络流 而且不以为耻反以为荣 解:首先按行扫描编号,如果在同一块中(即可以相互攻击),那么将其标为相同的数组,对列也做同样的操作. 然后扫描整张图,如果行编号 ...
- linux分区,文件系统,目录结构概述
1.Linux中如何表示硬盘,分区 Linux内核读取光驱,硬盘等资源时均通过“设备文件”的形式进行,因此在linux系统中,将硬 盘和分区表示为不同的文件.具体表述形式如下: 硬盘:对于IDE接口的 ...
- Swift流程控制之循环语句和判断语句详解
Swift提供了所有c类语言的控制流结构.包括for和while循环来执行一个任务多次:if和switch语句来执行确定的条件下不同的分支的代码:break和continue关键字能将运行流程转到你代 ...
- 【数学水题】【TOJ4113】【 Determine X】
题目大意: yuebai has a long sequence of integers A1,A2,-,AN. He also has such a function: F(x)=∑i=1N(⌊Ai ...
- 【类克鲁斯卡尔做法+枚举最小边】【HDU1598】【find the most comfortable road】
题意: 给你一个图,有边权,K个询问:u到v 的路径中 边权最大值-边权最小值的最小值是多少 http://acm.hdu.edu.cn/showproblem.php?pid=1598 题解( ...
- 关于HTML css的一些题目
1.dcutype是什么,他是干嘛用的 doctype是文档的一种声明,告诉浏览器器用什么规则来解析文档. 2.ul ol dl分别适用于什么地方? ul无序列表 ol有序列表 dl是定义列表,会默认 ...
- JQuery EasyUi 扩展combox验证
随笔记录一下 1.通过select text的值验证 /** * 扩展combox验证,easyui原始只验证select text的值,不支持value验证() */ (function($){ c ...