SharpZipLib
Available downloads
Assemblies for .NET 1.1, .NET 2.0 (3.5, 4.0), .NET CF 1.0, .NET CF 2.0: Download [237 KB]
Source code and samples Download [708 KB]
Help file Download [1208 KB]
参考博文:
ZipHelper.cs
1 using System;
2 using System.Data;
3 using System.Configuration;
4 using System.Linq;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.HtmlControls;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Xml.Linq;
12 using System.IO;
13 using ICSharpCode.SharpZipLib.Zip;
14
15 ///<summary>
16 ///ZipHelper 的摘要说明
17 ///</summary>
18 publicclass ZipHelper
19 {
20 ///<summary>
21 /// 创建ZipHelper实例
22 ///</summary>
23 publicstaticreadonly ZipHelper Instance =new ZipHelper();
24
25 private ZipHelper() { }
26
27 ///<summary>
28 /// 压缩文件
29 ///</summary>
30 ///<param name="zipFileName">文件名</param>
31 ///<param name="sourceDirectory">源文件目录</param>
32 publicvoid CreateZip(string zipFileName, string sourceDirectory)
33 {
34 FastZip fastZip =new FastZip();
35
36 try
37 {
38 fastZip.CreateEmptyDirectories =true;
39 fastZip.CreateZip(zipFileName, sourceDirectory, true, "");
40 }
41 catch (Exception ex)
42 {
43 thrownew Exception(ex.Message);
44 }
45 finally
46 {
47 fastZip =null;
48 }
49 }
50
51 ///<summary>
52 /// 解压文件
53 ///</summary>
54 ///<param name="zipFileName">文件名</param>
55 ///<param name="targetDirectory">目标文件目录</param>
56 publicvoid ExtractZip(string zipFileName, string targetDirectory)
57 {
58 FastZip fastZip =new FastZip();
59
60 try
61 {
62 fastZip.ExtractZip(zipFileName, targetDirectory, "");
63 }
64 catch (Exception ex)
65 {
66 thrownew Exception(ex.Message);
67 }
68 finally
69 {
70 fastZip =null;
71 }
72 }
73 }
74
2 using System.Data;
3 using System.Configuration;
4 using System.Linq;
5 using System.Web;
6 using System.Web.Security;
7 using System.Web.UI;
8 using System.Web.UI.HtmlControls;
9 using System.Web.UI.WebControls;
10 using System.Web.UI.WebControls.WebParts;
11 using System.Xml.Linq;
12 using System.IO;
13 using ICSharpCode.SharpZipLib.Zip;
14
15 ///<summary>
16 ///ZipHelper 的摘要说明
17 ///</summary>
18 publicclass ZipHelper
19 {
20 ///<summary>
21 /// 创建ZipHelper实例
22 ///</summary>
23 publicstaticreadonly ZipHelper Instance =new ZipHelper();
24
25 private ZipHelper() { }
26
27 ///<summary>
28 /// 压缩文件
29 ///</summary>
30 ///<param name="zipFileName">文件名</param>
31 ///<param name="sourceDirectory">源文件目录</param>
32 publicvoid CreateZip(string zipFileName, string sourceDirectory)
33 {
34 FastZip fastZip =new FastZip();
35
36 try
37 {
38 fastZip.CreateEmptyDirectories =true;
39 fastZip.CreateZip(zipFileName, sourceDirectory, true, "");
40 }
41 catch (Exception ex)
42 {
43 thrownew Exception(ex.Message);
44 }
45 finally
46 {
47 fastZip =null;
48 }
49 }
50
51 ///<summary>
52 /// 解压文件
53 ///</summary>
54 ///<param name="zipFileName">文件名</param>
55 ///<param name="targetDirectory">目标文件目录</param>
56 publicvoid ExtractZip(string zipFileName, string targetDirectory)
57 {
58 FastZip fastZip =new FastZip();
59
60 try
61 {
62 fastZip.ExtractZip(zipFileName, targetDirectory, "");
63 }
64 catch (Exception ex)
65 {
66 thrownew Exception(ex.Message);
67 }
68 finally
69 {
70 fastZip =null;
71 }
72 }
73 }
74