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 ...
随机推荐
- aoj 0118 Property Distribution
タナカ氏が HW アールの果樹園を残して亡くなりました.果樹園は東西南北方向に H × W の区画に分けられ.区画ごとにリンゴ.カキ.ミカンが植えられています.タナカ氏はこんな遺言を残していました. ...
- WPF GridViewColumn Sort DataTemplate
wpf的GridViewColumn的排序要用到ICollectionView 的SortDescriptions. SortDescriptions数组里是 SortDescription, S ...
- AndroidStudio启动时不自动打开项目
取消勾选Reopen last project on startup选项 点击 OK 就行了
- ng2父子模块数据交互
一.父模块向子模块传值 //父html <my-child [childdata]="parentdata"></my-child> 其中,my-child ...
- C#自定义控件 类似于Linechart
界面效果: 对外提供的属性设置 /// <summary> /// 背景色 /// </summary> public Color BackColor; /// <sum ...
- vue 之 折线图挤压
当tab标签栏变动时,echarts图会发生挤,这种情况,发现是html容器的width=100%这个设置,变成了width=100px. 解决方式: 1.设置一个最小宽度,获取width的值,当这个 ...
- Spring入门第十五课
泛型依赖注入 看代码: package logan.spring.study.generic.di; public class BaseRepository<T> { } package ...
- [Xcode 实际操作]六、媒体与动画-(3)使用CoreImage框架设置图片的单色效果
目录:[Swift]Xcode实际操作 本文将演示如何使用图片框架,将图片转换成单色样式. 在项目导航区,打开视图控制器的代码文件[ViewController.swift] import UIKit ...
- nginx 反向代理配置 upstream
最近项目要写后台,用nodejs写服务接口,然后研究了下nginx反向代理,各种坑下来,也总算把代理配了下来. 我本地用nodejs起了两个服务,一个端口是8888,一个端口是8889,在启动ngin ...
- java使用Robot类在eclipse上实现自动编写代码
运行时,把输入法关掉,切换成系统自带的输入法即可: 第二个类是自定义的键值Map集合,主要是为了方便输入字符串,有需要的可以自行添加: 主要的代码如下,会创建一个名称为Automaton.java的类 ...