zip (ICSharpCode.SharpZipLib.dll文件需要下载)
ZipClass zc=new ZipClass ();
zc.ZipDir(@"E:\1\新建文件夹", @"E:\1\新建文件夹.zip", 1);//压缩
zc.UnZip(@"E:\1\新建文件夹.zip",@"E:\1\2222");//解压
cs
class ZipClass
{
public void UnZip(string zipFilePath, string unZipDir)
{
if (zipFilePath == string.Empty)
{
throw new Exception("压缩文件不能为空!");
}
if (!File.Exists(zipFilePath))
{
throw new System.IO.FileNotFoundException("压缩文件不存在!");
}
//解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
if (unZipDir == string.Empty)
unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
if (!unZipDir.EndsWith("//"))
unZipDir += "//";
if (!Directory.Exists(unZipDir))
Directory.CreateDirectory(unZipDir); using (ZipInputStream s = new ZipInputStream(File.OpenRead(zipFilePath)))
{ ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);
if (directoryName.Length > )
{
Directory.CreateDirectory(unZipDir + directoryName);
}
if (!directoryName.EndsWith("//"))
directoryName += "//";
if (fileName != String.Empty)
{
using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))
{ int size = ;
byte[] data = new byte[];
while (true)
{
size = s.Read(data, , data.Length);
if (size > )
{
streamWriter.Write(data, , size);
}
else
{
break;
}
}
}
}
}
}
} public static void ZipDir(string sDir, string sZip, ZipOutputStream s)
{
string[] filenames = Directory.GetFiles(sDir);
string[] dirnames = Directory.GetDirectories(sDir);
Crc32 crc = new Crc32();
if (s == null)
{
s = new ZipOutputStream(File.Create(sZip));
s.SetLevel(); // 0 - store only to 9 - means best compression
} foreach (string file in filenames)
fileZipInStream(file, s); foreach (string dir in dirnames)
ZipDir(dir, "", s);
if (sZip != "")
{
s.Finish();
s.Close(); FileInfo fInfo = new FileInfo(sZip);
long size = fInfo.Length;
//Log.WriteLogD("----------------" + size.ToString());
if (size < )
File.Delete(sZip);
}
} }
ICSharpCode.SharpZipLib.dll下载地址:http://i.cnblogs.com/Files.aspx
感谢提供此类的朋友
zip (ICSharpCode.SharpZipLib.dll文件需要下载)的更多相关文章
- C# ICSharpCode.SharpZipLib.dll文件压缩和解压功能类整理,上传文件或下载文件很常用
工作中我们很多时候需要进行对文件进行压缩,比较通用的压缩的dll就是ICSharpCode.SharpZipLib.dll,废话不多了,网上也有很多的资料,我将其最常用的两个函数整理了一下,提供了一个 ...
- C# ZipHelper C#公共类 -- ICSharpCode.SharpZipLib.dll实现压缩和解压
关于本文档的说明 本文档基于ICSharpCode.SharpZipLib.dll的封装,常用的解压和压缩方法都已经涵盖在内,都是经过项目实战积累下来的 1.基本介绍 由于项目中需要用到各种压缩将文件 ...
- C#文件或文件夹压缩和解压方法(通过ICSharpCode.SharpZipLib.dll)
我在网上收集一下文件的压缩和解压的方法,是通过ICSharpCode.SharpZipLib.dll 来实现的 一.介绍的目录 第一步:下载压缩和解压的 ICSharpCode.SharpZipLib ...
- C# 下利用ICSharpCode.SharpZipLib.dll实现文件/目录压缩、解压缩
ICSharpCode.SharpZipLib.dll下载地址 1.压缩某个指定文件夹下日志,将日志压缩到CompressionDirectory文件夹中,并清除原来未压缩日志. #region 压缩 ...
- ICSharpCode.SharpZipLib.dll,MyZip.dll,Ionic.Zip.dll 使用
MyZip.dll : 有BUG,会把子目录的文件解压到根目录.. ICSharpCode.SharpZipLib.dll: 把ICSharpCode.SharpZipLib.dll复制一份,重命名为 ...
- C#使用ICSharpCode.SharpZipLib.dll压缩多个文件
首先通过NuGet管理安装ICSharpCode.SharpZipLib.dll 以下是压缩的通用方法: using System; using System.IO; using System.Web ...
- C# 压缩文件 ICSharpCode.SharpZipLib.dll
效果: 代码只能压缩文件夹里面的文件,不能压缩文件夹. 压缩前: 压缩后: 代码: 需要引用ICSharpCode.SharpZipLib.dll public ActionResult Index( ...
- ICSharpCode.SharpZipLib.dll 压缩多文件
网站:http://icsharpcode.github.io/SharpZipLib/ 引用:ICSharpCode.SharpZipLib.dll private string CompassZi ...
- ICSharpCode.SharpZipLib.dll 移植WP
由于众所周知的原因. ICSharpCode.SharpZipLib.dll在Unity移植WP的时候出现诸多API不兼容,解决方案是在在Github上面找ICSharpCode.SharpZipLi ...
随机推荐
- AndyQsmart ACM学习历程——ZOJ3870 Team Formation(位运算)
Description For an upcoming programming contest, Edward, the headmaster of Marjar University, is for ...
- windwos 10 谷歌浏览器出现彩色闪条
应该是上个星期五开始,发现电脑从别的地方切换到谷歌浏览器就会出现闪条,开始也没太注意,但是到周一还是这样,所以再网上查了下, 说什么的都有,什么你按脑屏幕坏了,内存条不行什么是的.后来才发现原来是谷歌 ...
- poj1149PIGS——网络最大流
题目:http://poj.org/problem?id=1149 不把猪圈当做点,而把顾客当作点,把猪当作边权(流量): 因为猪圈中的猪可流动,所以共用一个猪圈的人互相连边: 注意应该连成链的形式, ...
- 虚拟机VMware Workstation cannot connect to the virtual machine
解决方法: 从提示消息我们可以看到,问题在于VMware授权服务没有开启,具体处理方法如下: "This PC(我的电脑)"---右键"manage(管理)"- ...
- docker 学习(一)什么是Docker
项目中用到docker,就学习一下.第一篇是介绍. Sandboxie(沙箱):一个虚拟系统程序,允许你在沙盘环境中运行浏览器或其他程序,因此运行所产生的变化可以随后删除.它创造了一个类似沙盒的独立作 ...
- LeafLet之气泡框隐藏"x"图标
例子:var marker.bindPopup( "我是一个图标的文本", { minWidth: 300 }).openPopup();L.Popup Constructor(函 ...
- GridSplitter用法
1.GridSplitter的ShowsPreview设置为True时拖动报null错误 解决方法在Grid外面包装一个装饰器:AdornerDecorator,至于为什么这么做,暂时还不知道 2.当 ...
- 2019计蒜之道初赛4 B. 腾讯益智小游戏—矩形面积交(简单)(矩形交集)
B. 腾讯益智小游戏—矩形面积交(简单) 1000ms 262144K 腾讯游戏开发了一款全新的编程类益智小游戏,最新推出的一个小游戏题目是关于矩形面积交的.聪明的你能解出来吗?看下面的题目接招吧 ...
- HDU - 3001 Travelling(三进制状压dp)
Travelling After coding so many days,Mr Acmer wants to have a good rest.So travelling is the best ch ...
- 51Nod - 1092 回文字符串(添加删除字符LCS变形)
回文字符串 回文串是指aba.abba.cccbccc.aaaa这种左右对称的字符串.每个字符串都可以通过向中间添加一些字符,使之变为回文字符串. 例如:abbc 添加2个字符可以变为 acbbca, ...