新建一个项目,首先添加 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. Swift学习笔记五

    基础运算符 Swift的大部分运算符和C及OC相同,也分一元二元多元的,这里只记录一些Swift特有的性质或写法. 赋值运算符( = ) 在等号右边是一个有多个值的元组时,它的成员值可以分解并同时分别 ...

  2. Javascript可变长度参数列表 - Arguments对象

    在一个函数体内,标识符arguments具有特殊含义. Arguments对象是一个类似数组的对象 eg: 验证函数参数的正确数目 function f(x, y, z) { if (argument ...

  3. 使用C# 生成word记录

    private void button1_Click(object sender, System.EventArgs e) { object oMissing = System.Reflection. ...

  4. 返回ListBox选中的多项目

    //返回ListBox选中的多项目 procedure TForm1.Button2Click(Sender: TObject);vari:Integer;s:string;begin   for i ...

  5. android拦截短信并屏蔽系统的Notification

    拦截短信有几个关键点: 1.android接收短信时是以广播的方式 2.程序只要在自己的Manifest.xml里加有"接收"SMS的权限 <uses-permission  ...

  6. leetcode -- Search for a Range (TODO)

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  7. yeelink使用笔记

    一.触发条件设置 下面是我在群113978926里获得的解释: 摩斯电码<pengdonglin137@qq.com>  13:15:26 触发规则有什么限制吗怎么我设置的条件有时候无效呢 ...

  8. VBA-工程-找不到工程或库-解决方案

    近来,越来越多的朋友被“找不到工程或库”的错误所烦恼,所以决定新开一帖来聊聊此问题! QUOTE: 一般情况下,出现此错误是因为找不到引用工程,或找不到与工程语言对应的引用的对象库 出现此类错误可以根 ...

  9. HttpClient设置代理,超时,以及得到cookies

    import java.net.URI; import java.util.List; import org.apache.http.HttpEntity; import org.apache.htt ...

  10. Peter's Hobby

    Problem Description Recently, Peter likes to measure the humidity of leaves. He recorded a leaf humi ...