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. js中“原生”map

    var map = {}; // Map map = new HashMap(); map[key] = value; // map.put(key, value); var value = map[ ...

  2. RabbitMQ学习总结(5)——发布和订阅实例详解

    一.Publish/Subscribe(发布/订阅)(using the Java Client) 在前面的教程中,我们创建了一个work Queue(工作队列).工作队列背后的假设是每个任务是交付给 ...

  3. ASP.NET-Active Direcotry编程示例

    查找指定的AD帐号 using (DirectoryEntry de = new DirectoryEntry("LDAP://RootDSE")) { string DCName ...

  4. C++ throw的实验 & 异常类继承关系

    如果定义了 throw() 表示函数不抛出异常,这时候如果还是抛出,会导致运行时错误. #include <iostream> #include <exception> #in ...

  5. [Gatsby] Install Gatsby and Scaffold a Blog

    In this lesson, you’ll install Gatsby and the plugins that give the default starter the ability to t ...

  6. Apache shiro 笔记整理之编程式授权

    下面内容是在看了涛哥的<跟我一起学shiro> 和 视频<一头扎入进shiro> 后整理出来备忘和方便自己和其它人学习. 个人主页:http://www.itit123.cn/ ...

  7. html屏蔽鼠标右键

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 如何比较Keras, TensorLayer, TFLearn ?——如果只是想玩玩深度学习,想快速上手 -- Keras 如果工作中需要解决内部问题,想快速见效果 -- TFLearn 或者 Tensorlayer 如果正式发布的产品和业务,自己设计网络模型,需要持续开发和维护 -- Tensorlayer

    转自:https://www.zhihu.com/question/50030898/answer/235137938 如何比较Keras, TensorLayer, TFLearn ? 这三个库主要 ...

  9. Defining and using constants from PySide in QML

    Defining and using constants from PySide in QML This PySide tutorial shows you how to define constan ...

  10. [ZJOJ2014] 力 解题报告 (FFT)

    题目链接: https://www.luogu.org/problemnew/show/P3338 题目: 给出$n$个数$q_i$,令$F_j=\sum_{i<j}\frac{q_iq_j}{ ...