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文件需要下载)的更多相关文章

  1. C# ICSharpCode.SharpZipLib.dll文件压缩和解压功能类整理,上传文件或下载文件很常用

    工作中我们很多时候需要进行对文件进行压缩,比较通用的压缩的dll就是ICSharpCode.SharpZipLib.dll,废话不多了,网上也有很多的资料,我将其最常用的两个函数整理了一下,提供了一个 ...

  2. C# ZipHelper C#公共类 -- ICSharpCode.SharpZipLib.dll实现压缩和解压

    关于本文档的说明 本文档基于ICSharpCode.SharpZipLib.dll的封装,常用的解压和压缩方法都已经涵盖在内,都是经过项目实战积累下来的 1.基本介绍 由于项目中需要用到各种压缩将文件 ...

  3. C#文件或文件夹压缩和解压方法(通过ICSharpCode.SharpZipLib.dll)

    我在网上收集一下文件的压缩和解压的方法,是通过ICSharpCode.SharpZipLib.dll 来实现的 一.介绍的目录 第一步:下载压缩和解压的 ICSharpCode.SharpZipLib ...

  4. C# 下利用ICSharpCode.SharpZipLib.dll实现文件/目录压缩、解压缩

    ICSharpCode.SharpZipLib.dll下载地址 1.压缩某个指定文件夹下日志,将日志压缩到CompressionDirectory文件夹中,并清除原来未压缩日志. #region 压缩 ...

  5. ICSharpCode.SharpZipLib.dll,MyZip.dll,Ionic.Zip.dll 使用

    MyZip.dll : 有BUG,会把子目录的文件解压到根目录.. ICSharpCode.SharpZipLib.dll: 把ICSharpCode.SharpZipLib.dll复制一份,重命名为 ...

  6. C#使用ICSharpCode.SharpZipLib.dll压缩多个文件

    首先通过NuGet管理安装ICSharpCode.SharpZipLib.dll 以下是压缩的通用方法: using System; using System.IO; using System.Web ...

  7. C# 压缩文件 ICSharpCode.SharpZipLib.dll

    效果: 代码只能压缩文件夹里面的文件,不能压缩文件夹. 压缩前: 压缩后: 代码: 需要引用ICSharpCode.SharpZipLib.dll public ActionResult Index( ...

  8. ICSharpCode.SharpZipLib.dll 压缩多文件

    网站:http://icsharpcode.github.io/SharpZipLib/ 引用:ICSharpCode.SharpZipLib.dll private string CompassZi ...

  9. ICSharpCode.SharpZipLib.dll 移植WP

    由于众所周知的原因. ICSharpCode.SharpZipLib.dll在Unity移植WP的时候出现诸多API不兼容,解决方案是在在Github上面找ICSharpCode.SharpZipLi ...

随机推荐

  1. MySQL 数据底部出现总计字样 第二种办法 纵向合并 20161103

    上次在博客http://www.cnblogs.com/Mr-Cxy/p/5923375.html 我们使用了group by with rollup 函数 field自定义排序 来实现添加底部总计字 ...

  2. WC2017 冬眠记

    2017年2月3日,为期7天的冬眠营冬令营正式开幕. 前4天我们见到了各种集训队dalao们的华丽身姿 感受到了听课听不懂睡觉又惭愧的无力感 见到了几百号人近一半玩手机,剩下的一半有一半在睡觉,再剩下 ...

  3. BLE Mesh网络协议综述

    0 引言 自2012年蓝牙4.0规范推出之后,全新的蓝牙低功耗(BLE)技术由于其极低的运行和待机功耗.低成本和跨厂商互操作性,3 ms低延迟.AES-128加密等诸多特色,可以用于计步器.心律监视器 ...

  4. asp.net mvc 注册中的邮箱激活功能实现

    基本流程图 注册页面就不再写出,现在将发送邮件的代码粘贴出来   public ActionResult SendEmial() { ; string validataCode = System.Gu ...

  5. WPF学习系列之五(WPF控件)

    控件:    1.内容控件------这些控件能够包含嵌套的元素,为它们提供几乎无限的显示能力.内容控件包括Lable,Button 以及ToolTip类. 内容控件是更特殊的控件类型,它们可以包含( ...

  6. PCL中异常处理机制

    博客转载自:http://www.pclcn.org/study/shownews.php?lang=cn&id=287 本节我们主要讨论PCL在编写和应用过程中如何利用PCL的异常机制,提高 ...

  7. java&nbsp;POP3

    package com.skyzoo.Jutil; import java.io.BufferedReader; import java.io.IOException; import java.io. ...

  8. php中的PCRE 函数,正则表达式处理函数。

    有时候在一些特定的业务场景中需要匹配,或者提取一些关键的信息,例如匹配网页中的一些链接, 提取一些数据时,可能会用到正则匹配. 下面介绍一下php中的一些常用的正则处理函数. 一.preg_repla ...

  9. Laravel中使用Session存取验证码信息

    1.将验证码存储到session中. $request->session()->put('validate_code',$validateCode->getCode());//存储信 ...

  10. JavaScript操作服务器控件之Gridview控件

    1.JavaScript脚本如下: <script language="javascript" type="text/javascript">    ...