新建一个项目,首先添加 System.IO.Compression.FileSystem 引用。

解压文件

using System.IO.Compression;
namespace cl
{
static void Main()
{
string zipPath = @"c:\example\result.zip";
string extractPath = @"c:\example\extract";
ZipFile.ExtractToDirectory(zipPath, extractPath);
}
}

压缩单个文件

using System;
using System.IO.Compression; namespace cl
{
sealed class ZipCreater
{
static void Main()
{
using (var zip = ZipFile.Open("ZipCreater.zip", ZipArchiveMode.Create))
{
zip.CreateEntryFromFile(@"C:\work\ZipCreater.cs", "ZipCreater.cs");
zip.CreateEntryFromFile("ZipCreater.exe", "ZipCreater.exe");
}
}
}
}

压缩文件夹

using System;
using System.IO.Compression; namespace cl
{
sealed class Zip
{
static void Main(string[] args)
{
if (args.Length != )
{
Console.WriteLine("Usage: Zip zip-file-name directory-name");
return;
}
try { ZipFile.CreateFromDirectory(args[], args[]); }
catch (Exception ex) { Console.Error.WriteLine(ex.Message); }
}
}
}

参考文章:

浅谈 ZipArchive 类 - 银河 - 博客园
http://www.cnblogs.com/skyivben/archive/2012/03/09/2388482.html

ZipArchive 的使用的更多相关文章

  1. 文件打包,下载之使用PHP自带的ZipArchive压缩文件并下载打包好的文件

    总结:                                                          使用PHP下载文件的操作需要给出四个header(),可以参考我的另一篇博文: ...

  2. ZipArchive之C++编译和调用

    由于要用到zip的解压,就上网下载了CZipArchive类的源码(还是2000年的),里面有个示例,稍微修改下,就能正常运行. 就高兴地把lib拿出来,放到项目中了.捣鼓了快一个下午了,死活编译不通 ...

  3. ZipArchive 打包下载压缩包

    用php的header()方式下载压缩包. 要点:1.不能在header导出压缩包前向浏览器输出内容,否则文件下载压缩包成功,打开的压缩包也会显示被破坏. 2.在压缩文件包的php代码前不可以有js脚 ...

  4. iOS开发——网络篇——文件下载(NSMutableData、NSFileHandle、NSOutputStream)和上传、压缩和解压(三方框架ZipArchive),请求头和请求体格式,断点续传Range

    一.小文件下载 NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/resources/images/minion ...

  5. ZipArchive和SSZipArchive使用详解

    一.SSZipArchive 1.简介 SSZipArchive是iOS和Mac上一个简单实用的压缩和解压插件.用途包括:1.解压zip文件:2.解压密码保护的ZIP文件:3.创建新的zip文件:4. ...

  6. zipArchive

    ZipArchive *unZip = [[ZipArchive alloc]init]; if ([unZip unzipOpenFile:savePath]) { BOOL ret = [unZi ...

  7. 代码演示用 .NET 4.5 (C# 5.0)自带的压缩类 ZipArchive 创建一个压缩文件

    代码如下: using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; ...

  8. ZipArchive框架的文件压缩和解压

    导入第三方框架ZipArchive之后还要在系统库文件中导入一个如下文件(搜索libz出来的任何一个都可以)   导入的头文件是#import "Main.h" 文件压缩 -(vo ...

  9. Fatal error: Class 'ZipArchive' not found的解决办法

    今天在Linux底下编写导出EXCEL文件并显示输出时,抛出“ZipArchive library is not enabled” 的异常.而我在本地的windows下的代码则是运行正常的. 原因是: ...

随机推荐

  1. 如何将mysql表结构导出成Excel格式的(并带备注)

    http://www.liangchan.net/liangchan/4561.html 1.使用一个mysql管理工具:SQLyog,点击菜单栏“数据库”下拉的最后一项: 导出的格式如下: 2.要想 ...

  2. MySQL几个注意点

    1.在创建表.对表进行操作之前,必须首先选择数据库.通过 mysql_select_db() 函数选取数据库.当您创建 varchar 类型的数据库字段时,必须规定该字段的最大长度,例如:varcha ...

  3. 对PostgreSQL中 pg_各表的RelationId的认识

    读取普通的table或者系统表,都会调用heap_open函数: /* ---------------- * heap_open - open a heap relation by relation ...

  4. Hibernate征途(七)之复合主键映射和集合映射

    把这两种映射放到一起说,是因为这两种映射不像前面的复用型映射.数量和方向型映射那么分类鲜明,所以放到了这个“其他”里面. 复合主键映射 在关系模型中,复合主键和其他的主键方式没有很大区别,但是反映到对 ...

  5. webqq 获得好友列表hash算法 获得最新hash的方法

    webqq获得好友列表的hash算法,大约每一个月中旬会变动一次.知道怎么获得他就能够了. js文件路径 http://web.qstatic.com/webqqpic/pubapps/0/50/eq ...

  6. zoj 3511 Cake Robbery(线段树)

    problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...

  7. [Javascript] Monads

    Monads allow you to nest computations. They are a pointed functor that adds mjoin and chain function ...

  8. Node.js 的Web server--Fenix

    Fenix 是提供给开发者使用的简单的一个 Web server, 是基于 Node.js 开发. 能够同一时候在上面执行非常多的项目. 最适合前端开发者使用. 能够通过免费的 Node.js 控制台 ...

  9. divide-conquer-combine(4.1 from the introduction to algorithm)

    this example is from chapter 4 in <the introduction to algorithm> the main idea is all showed ...

  10. MySQL_update同一张表

    update tb1 inner join(select type, count(*) as cntfrom tb1 group by type)as der using(type)set tb1.c ...