[Asp.net]ZipHelper 在線壓縮解壓協助類(SharpZipLib組件實現)

來源:互聯網
上載者:User

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]

參考博文:

SharpZipLib使用樣本 - lann - 部落格園

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.