C# 解压及压缩文件源代码
using System.IO;
using System.Windows.Forms;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Checksums;
public void unZip(string strSouceFile, string strDestFile)
{
if (!Directory.Exists(strDestFile))
Directory.CreateDirectory(strDestFile);
using (ZipInputStream zip = new ZipInputStream(File.OpenRead(strSouceFile)))
{
ZipEntry theEntry;
string fileName;
FileStream streamWriter;
while ((theEntry = zip.GetNextEntry()) != null)
{
fileName = Path.GetFileName(theEntry.Name); if (fileName != String.Empty)
{
streamWriter = new FileStream(strDestFile + fileName, FileMode.Create, FileAccess.Write, FileShare.Read | FileShare.Write); int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = zip.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size); }
else
{
break;
}
}
streamWriter.Close();
}
}
MessageBox.Show("解压文件成功! ","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
} public void ZipFile(string strSouceFile, string strDestFile)
{
using (ZipOutputStream stream = new ZipOutputStream(File.Create(strDestFile)))
{
stream.SetLevel(5);
byte[] buffer = new byte[0x1000];
ZipEntry entry = new ZipEntry(Path.GetFileName(strSouceFile));
entry.DateTime = DateTime.Now;
stream.PutNextEntry(entry);
using (FileStream stream2 = File.OpenRead(strSouceFile))
{
int num;
do
{
num = stream2.Read(buffer, 0, buffer.Length);
stream.Write(buffer, 0, num);
}
while (num > 0);
MessageBox.Show("压缩文件成功! ");
}
stream.Finish();
stream.Close();
}
}
须要引用的dll,下载下面页面的dll
http://download.csdn.net/detail/sky_cat/7236675
C# 解压及压缩文件源代码的更多相关文章
- [转]Ubuntu Linux 安装 .7z 解压和压缩文件
[转]Ubuntu Linux 安装 .7z 解压和压缩文件 http://blog.csdn.net/zqlovlg/article/details/8033456 安装方法: sudo apt-g ...
- 【VC++技术杂谈008】使用zlib解压zip压缩文件
最近因为项目的需要,要对zip压缩文件进行批量解压.在网上查阅了相关的资料后,最终使用zlib开源库实现了该功能.本文将对zlib开源库进行简单介绍,并给出一个使用zlib开源库对zip压缩文件进行解 ...
- C#利用SharpZipLib解压或压缩文件夹实例操作
最近要做一个项目涉及到C#中压缩与解压缩的问题的解决方法,大家分享. 这里主要解决文件夹包含文件夹的解压缩问题. )下载SharpZipLib.dll,在http://www.icsharpcode. ...
- C# 解压RAR压缩文件
此方法适用于C盘windows文件夹中有WinRAR.exe文件 /// 解压文件(不带密码) RAR压缩程序 返回解压出来的文件数量 /// </summary> /// <par ...
- C#解压或压缩文件夹
这里主要解决文件夹包含文件夹的解压缩问题.1)下载SharpZipLib.dll,在http://www.icsharpcode.net/OpenSource /SharpZipLib/Downloa ...
- C# 解压zip压缩文件
此方法需要在程序内引用ICSharpCode.SharpZipLib.dll 类库 /// <summary> /// 功能:解压zip格式的文件. /// </summary> ...
- [转]Ubuntu Linux 安装 .7z 解压和压缩文件
原文网址:http://blog.csdn.net/zqlovlg/article/details/8033456 安装方法: sudo apt-get install p7zip-full 解压文件 ...
- C# 解压与压缩文件
解压文件 ,引用 SharpZipLib.dll类库 方法一: public void UnGzipFile(string zipfilename) { //同压缩文件同级同名的非压缩文件路径 var ...
- golang zip 解压、压缩文件
package utils import ( "archive/zip" "fmt" "io" "io/i ...
随机推荐
- 原生ajax的请求过程
原生ajax的请求过程 创建全平台兼容的XMLHttpRequest对象: function getXHR(){ var xhr = null; if(window.XMLHttpRequest) { ...
- Reentrant protected mode kernel using virtual 8086 mode interrupt service routines
A method for allowing a protected mode kernel to service, in virtual 8086 mode, hardware interrupts ...
- Core abstraction layer for telecommunication network applications
A new sub-system, the core abstraction layer (CAL), is introduced to the middleware layer of the mul ...
- 一个通用Makefile的编写
作者:杨老师,华清远见嵌入式学院讲师. 我们在Linux环境下开发程序,少不了要自己编写Makefile,一个稍微大一些的工程下面都会包含很多.c的源文件.如果我们用gcc去一个一个编译每一个源文件的 ...
- DSAPI多功能组件编程应用-DS提示气泡
首先下载DSAPI.dll.并在项目中引用. 该功能包括在DSAPI1.0.1.1及更高版本号,DLL请到本人资源里查找. Private Sub Button1_Click(sender As Ob ...
- ioctl.h 分析
ioctl.h 分析 我自己画了个解析图...不要嫌弃丑啊.. . 哈哈 type The magic number. Just choose one number (after consulting ...
- Partition(hdu4651)2013 Multi-University Training Contest 5----(整数拆分一)
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- firefox 被劫持hao123 主页
快捷方式没有问题 也不是ff的配置文件里user.js的问题 是haozip的问题 最后查到是windows/system/Hao*.sys 这个文件的问题(还有zolsoft.sys) 删除这个文件 ...
- JavaSE入门学习24:Java面向对象补充
一Java中的Object类 Object类是全部Java类的父类.假设一个类没有使用extendskeyword明白标识继承另外一个类,那么这个类默认 继承Object类. public class ...
- iOS学习必须了解的七大手势
文章只要你有一点点基础应该就可以看的懂,文章只为学习交流 #import "ViewController.h" @interface ViewController () @prop ...