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 ...
随机推荐
- 在WPF中自定义你的绘制(四)
原文:在WPF中自定义你的绘制(四) 在WPF中自定义你的绘制(四) ...
- python-django如何在sae中使用自带ImageField和FileField -django-上善若水小站
python-django如何在sae中使用自带ImageField和FileField -django-上善若水小站 python-django如何在sae中使用自带ImageField和FileF ...
- subllime text 创建可复用的代码片段
对于前端工程师来讲,写一个html页面的基本结构是体力活,每次去拷贝一个也麻烦,sublime text 2 提供了一个很好的复用代码片段.下面介绍一下创建一个html5的代码片段的过程. 在菜单上点 ...
- HDFS的运行原理(转载)
原文地址:http://www.cnblogs.com/laov/p/3434917.html 简介 HDFS(Hadoop Distributed File System )Hadoop分布式文件系 ...
- 页面样式base.css
下面是我用过多次的base.css.欢迎各种建议吐槽.大家共同进步. ;;} table{;} fieldset,img {;} address,caption, cite,code,dfn,em,s ...
- 前端开发必备的Sublime 3插件
Sublime的大名已经无需我介绍了,首先先介绍如何启用插件安装功能: 打开Sublime 3,然后按 ctrl+` 或者在View → Show Console 在打开的窗口里黏贴这个网站上的代码( ...
- 操作Sql数据库帮助类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- 2015.01.06 JQuery
jQuery是一个兼容多浏览器的javascript库.开发出来的JavaScript的脚本包.非侵入性的脚本. 下载地址:http://jquery.com/ (打不开网页需要翻* ...
- BFC块级排版上下文
1.BFC 全称是块级排版上下文,用于对块级元素排版,默认情况下只有根元素(body)一个块级上下文,但是如果一个块级元素 设置了float:left,overflow:hidden或position ...
- 对FineU框架Grid多表头合计行导出Excel的回顾
年前用FineUI开发遇到了这样一个问题,Grid多表头合计行不能导出,后面到官方示例找了一下,庆幸的是找到了多表头的导出示例.然后当时为了省事,直接就复制粘贴完事,也没有仔细的研究代码.后来运行一看 ...