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# 解压及压缩文件源代码的更多相关文章

  1. [转]Ubuntu Linux 安装 .7z 解压和压缩文件

    [转]Ubuntu Linux 安装 .7z 解压和压缩文件 http://blog.csdn.net/zqlovlg/article/details/8033456 安装方法: sudo apt-g ...

  2. 【VC++技术杂谈008】使用zlib解压zip压缩文件

    最近因为项目的需要,要对zip压缩文件进行批量解压.在网上查阅了相关的资料后,最终使用zlib开源库实现了该功能.本文将对zlib开源库进行简单介绍,并给出一个使用zlib开源库对zip压缩文件进行解 ...

  3. C#利用SharpZipLib解压或压缩文件夹实例操作

    最近要做一个项目涉及到C#中压缩与解压缩的问题的解决方法,大家分享. 这里主要解决文件夹包含文件夹的解压缩问题. )下载SharpZipLib.dll,在http://www.icsharpcode. ...

  4. C# 解压RAR压缩文件

    此方法适用于C盘windows文件夹中有WinRAR.exe文件 /// 解压文件(不带密码) RAR压缩程序 返回解压出来的文件数量 /// </summary> /// <par ...

  5. C#解压或压缩文件夹

    这里主要解决文件夹包含文件夹的解压缩问题.1)下载SharpZipLib.dll,在http://www.icsharpcode.net/OpenSource /SharpZipLib/Downloa ...

  6. C# 解压zip压缩文件

    此方法需要在程序内引用ICSharpCode.SharpZipLib.dll 类库 /// <summary> /// 功能:解压zip格式的文件. /// </summary> ...

  7. [转]Ubuntu Linux 安装 .7z 解压和压缩文件

    原文网址:http://blog.csdn.net/zqlovlg/article/details/8033456 安装方法: sudo apt-get install p7zip-full 解压文件 ...

  8. C# 解压与压缩文件

    解压文件 ,引用 SharpZipLib.dll类库 方法一: public void UnGzipFile(string zipfilename) { //同压缩文件同级同名的非压缩文件路径 var ...

  9. golang zip 解压、压缩文件

    package utils import (    "archive/zip"    "fmt"    "io"    "io/i ...

随机推荐

  1. Ajax兼容性问题

    对于IE7及以上直接使用 XMLHttpRequest 就行,但对于过老版本IE建议直接提示用户下载新版浏览器更佳.或者用以下代码兼容IE6: function CreateXHR() { if(XM ...

  2. nutch的一些基础整理

    nutch的一些基础整理 原创 2015年03月22日 18:18:01 标签: nutch / 240 编辑 删除 一.关于配置文件: nutch-default.xml:爬虫的默认配置.在${nu ...

  3. 洛谷—— P1260 工程规划

    https://www.luogu.org/problem/show?pid=1260 题目描述 造一幢大楼是一项艰巨的工程,它是由n个子任务构成的,给它们分别编号1,2,…,n(5≤n≤1000). ...

  4. QQ在线人数统计图数据解析

    转载请注明出处:http://blog.csdn.net/xiaoy_h/article/details/27980851 我相信非常多人一定去过这个地方: http://im.qq.com/onli ...

  5. Ruby print

    Ruby print

  6. 《从零開始学Swift》学习笔记(Day 46)——下标重写

    原创文章.欢迎转载.转载请注明:关东升的博客 下标是一种特殊属性. 子类属性重写是重写属性的getter和setter訪问器,对下标的重写也是重写下标的getter和setter訪问器. 以下看一个演 ...

  7. DSAPI多功能组件编程应用-DS提示气泡

    首先下载DSAPI.dll.并在项目中引用. 该功能包括在DSAPI1.0.1.1及更高版本号,DLL请到本人资源里查找. Private Sub Button1_Click(sender As Ob ...

  8. IBM AppScan官方帮助文档错别字缺陷,IBM的測试人员也太粗心了吧

    袁术=元素?

  9. Swift 3.0(一)

    一:let 和 var let 声明的是一个常量, var 声明的是一个变量 二:简单数据类型 1.自推出数据类型 let implicitDouble = 70.0    //根据初始化时赋值的数据 ...

  10. m_Orchestrate learning system---十一、thinkphp查看临时文件的好处是什么

    m_Orchestrate learning system---十一.thinkphp查看临时文件的好处是什么 一.总结 一句话总结:可以知道thinkphp的标签被smarty引擎翻译而来的php代 ...