首先 需要下载DotNetZip的组件
http://dotnetzip.codeplex.com/
在项目中引入Ionic.Zip
引入名字空间
using System.Text;
using Ionic.Zip;
压缩
public static void zipDir(string source,string target) { //source d:test //target d:/mytest.zip using (ZipFile zip = new ZipFile(Encoding.UTF8)) { zip.AddDirectory(source); zip.Save(target); } }
解压缩
public static void enZip(string source, string target) { //source "d:/Archive.zip" target"d:/newtest" using (ZipFile zip = ZipFile.Read(source)) { zip.ExtractAll(target); } }
要使用密码的话 zip.Password = "123456";