(一). 实现功能
    对文件及目录的压缩及解压功能
(二). 运行图片示例

(三).代码
1. 压缩类
  1 /// <summary>
/// <summary>
2 /// 压缩类
/// 压缩类
3 /// </summary>
/// </summary>
4 public class ZipClass
public class ZipClass
5 {
{   
6 public static void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize)
    public static void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize)
7 {
    {
8 //如果文件没有找到,则报错
        //如果文件没有找到,则报错
9 if (!System.IO.File.Exists(FileToZip))
        if (!System.IO.File.Exists(FileToZip))
10 {
        {
11 throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
            throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
12 }
        }
13
14 System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
15 System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
        System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
16 ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
        ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
17 ZipEntry ZipEntry = new ZipEntry("ZippedFile");
        ZipEntry ZipEntry = new ZipEntry("ZippedFile");
18 ZipStream.PutNextEntry(ZipEntry);
        ZipStream.PutNextEntry(ZipEntry);
19 ZipStream.SetLevel(CompressionLevel);
        ZipStream.SetLevel(CompressionLevel);
20 byte[] buffer = new byte[BlockSize];
        byte[] buffer = new byte[BlockSize];
21 System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
        System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
22 ZipStream.Write(buffer, 0, size);
        ZipStream.Write(buffer, 0, size);
23 try
        try
24 {
        {
25 while (size < StreamToZip.Length)
            while (size < StreamToZip.Length)
26 {
            {
27 int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
                int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
28 ZipStream.Write(buffer, 0, sizeRead);
                ZipStream.Write(buffer, 0, sizeRead);
29 size += sizeRead;
                size += sizeRead;
30 }
            }
31 }
        }
32 catch (System.Exception ex)
        catch (System.Exception ex)
33 {
        {
34 throw ex;
            throw ex;
35 }
        }
36 ZipStream.Finish();
        ZipStream.Finish();
37 ZipStream.Close();
        ZipStream.Close();
38 StreamToZip.Close();
        StreamToZip.Close();
39 }
    }
40
41 /// <summary>
    /// <summary>
42 /// 压缩目录
    /// 压缩目录
43 /// </summary>
    /// </summary>
44 /// <param name="args">数组(数组[0]: 要压缩的目录; 数组[1]: 压缩的文件名)</param>
    /// <param name="args">数组(数组[0]: 要压缩的目录; 数组[1]: 压缩的文件名)</param>
45 public static void ZipFileDictory(string[] args)
    public static void ZipFileDictory(string[] args)
46 {
    {
47 string[] filenames = Directory.GetFiles(args[0]);
        string[] filenames = Directory.GetFiles(args[0]);
48
49 Crc32 crc = new Crc32();
        Crc32 crc = new Crc32();
50 ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
        ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));            
51 s.SetLevel(6);
        s.SetLevel(6); 
52 foreach (string file in filenames)
        foreach (string file in filenames)
53 {
        {
54 //打开压缩文件
            //打开压缩文件
55 FileStream fs = File.OpenRead(file);
            FileStream fs = File.OpenRead(file);
56
57 byte[] buffer = new byte[fs.Length];
            byte[] buffer = new byte[fs.Length];
58 fs.Read(buffer, 0, buffer.Length);
            fs.Read(buffer, 0, buffer.Length);
59 ZipEntry entry = new ZipEntry(file);
            ZipEntry entry = new ZipEntry(file);
60
61 entry.DateTime = DateTime.Now;
            entry.DateTime = DateTime.Now;
62 
            
63 entry.Size = fs.Length;
            entry.Size = fs.Length;
64 fs.Close();
            fs.Close();
65
66 crc.Reset();
            crc.Reset();
67 crc.Update(buffer);
            crc.Update(buffer);
68
69 entry.Crc = crc.Value;
            entry.Crc = crc.Value;
70
71 s.PutNextEntry(entry);
            s.PutNextEntry(entry);
72
73 s.Write(buffer, 0, buffer.Length);
            s.Write(buffer, 0, buffer.Length);
74
75 }
        }
76
77 s.Finish();
        s.Finish();
78 s.Close();
        s.Close();
79 }
    }
80
81 /// <summary>
    /// <summary>
82 /// 压缩文件
    /// 压缩文件
83 /// </summary>
    /// </summary>
84 /// <param name="FileToZip">要进行压缩的文件名</param>
    /// <param name="FileToZip">要进行压缩的文件名</param>
85 /// <param name="ZipedFile">压缩后生成的压缩文件名</param>
    /// <param name="ZipedFile">压缩后生成的压缩文件名</param>
86 public static void ZipFile(string FileToZip, string ZipedFile)
    public static void ZipFile(string FileToZip, string ZipedFile)
87 {
    {
88 //如果文件没有找到,则报错
        //如果文件没有找到,则报错
89 if (!File.Exists(FileToZip))
        if (!File.Exists(FileToZip))
90 {
        {
91 throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
            throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
92 }
        }            
93 FileStream fs = File.OpenRead(FileToZip);
        FileStream fs = File.OpenRead(FileToZip);
94 byte[] buffer = new byte[fs.Length];
        byte[] buffer = new byte[fs.Length];
95 fs.Read(buffer, 0, buffer.Length);
        fs.Read(buffer, 0, buffer.Length);
96 fs.Close();
        fs.Close();
97
98 FileStream ZipFile = File.Create(ZipedFile);
        FileStream ZipFile = File.Create(ZipedFile);
99 ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
        ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
100 ZipEntry ZipEntry = new ZipEntry("ZippedFile");
        ZipEntry ZipEntry = new ZipEntry("ZippedFile");
101 ZipStream.PutNextEntry(ZipEntry);
        ZipStream.PutNextEntry(ZipEntry);
102 ZipStream.SetLevel(6);
        ZipStream.SetLevel(6);
103 
        
104 ZipStream.Write(buffer, 0, buffer.Length);
        ZipStream.Write(buffer, 0, buffer.Length);            
105 ZipStream.Finish();
        ZipStream.Finish();
106 ZipStream.Close();
        ZipStream.Close();
107 }
    }
108 }
}
109
110 /// <summary>
/// <summary>
111 ///  解压类
///  解压类
112 /// </summary>
/// </summary>
113 public class UnZipClass
public class UnZipClass
114 {
{
115 /// <summary>
    /// <summary>
116 /// 解压功能(解压压缩文件到指定目录)
    /// 解压功能(解压压缩文件到指定目录)
117 /// </summary>
    /// </summary>
118 /// <param name="args">待解压的文件</param>
    /// <param name="args">待解压的文件</param>
119 /// <param name="args">指定解压目标目录</param>
    /// <param name="args">指定解压目标目录</param>
120 public static void UnZip(string[] args)
    public static void UnZip(string[] args)
121 {
    {
122 ZipInputStream s = new ZipInputStream(File.OpenRead(@args[0].Trim()));
        ZipInputStream s = new ZipInputStream(File.OpenRead(@args[0].Trim()));            
123 ZipEntry theEntry;
        ZipEntry theEntry;
124 string directoryName = Path.GetDirectoryName(@args[1].Trim());
        string directoryName = Path.GetDirectoryName(@args[1].Trim());
125 
        
126 if (!Directory.Exists(@args[1].Trim()))
        if (!Directory.Exists(@args[1].Trim()))
127 {
        {
128 Directory.CreateDirectory(directoryName);
            Directory.CreateDirectory(directoryName);
129 }
        }
130 while ((theEntry = s.GetNextEntry()) != null)
        while ((theEntry = s.GetNextEntry()) != null)
131 {
        {
132 ;
            ;
133 string fileName = Path.GetFileName(theEntry.Name);
            string fileName = Path.GetFileName(theEntry.Name);
134
135 if (fileName != String.Empty)
            if (fileName != String.Empty)
136 {
            {            
137 FileStream streamWriter = File.Create(@args[1].Trim() + fileName);
                FileStream streamWriter = File.Create(@args[1].Trim() + fileName);
138
139 int size = 2048;
                int size = 2048;
140 byte[] data = new byte[2048];
                byte[] data = new byte[2048];
141 while (true)
                while (true)
142 {
                {
143 size = s.Read(data, 0, data.Length);
                    size = s.Read(data, 0, data.Length);
144 if (size > 0)
                    if (size > 0)
145 {
                    {
146 streamWriter.Write(data, 0, size);
                        streamWriter.Write(data, 0, size);
147 }
                    }
148 else
                    else
149 {
                    {
150 break;
                        break;
151 }
                    }
152 }
                }
153
154 streamWriter.Close();
                streamWriter.Close();
155 }
            }
156 }
        }
157 s.Close();
        s.Close();
158 }
    }
159
 /// <summary>
/// <summary>2
 /// 压缩类
/// 压缩类3
 /// </summary>
/// </summary>4
 public class ZipClass
public class ZipClass5
 {
{   6
 public static void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize)
    public static void ZipFile(string FileToZip, string ZipedFile, int CompressionLevel, int BlockSize)7
 {
    {8
 //如果文件没有找到,则报错
        //如果文件没有找到,则报错9
 if (!System.IO.File.Exists(FileToZip))
        if (!System.IO.File.Exists(FileToZip))10
 {
        {11
 throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
            throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");12
 }
        }13

14
 System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);
        System.IO.FileStream StreamToZip = new System.IO.FileStream(FileToZip, System.IO.FileMode.Open, System.IO.FileAccess.Read);15
 System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);
        System.IO.FileStream ZipFile = System.IO.File.Create(ZipedFile);16
 ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
        ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);17
 ZipEntry ZipEntry = new ZipEntry("ZippedFile");
        ZipEntry ZipEntry = new ZipEntry("ZippedFile");18
 ZipStream.PutNextEntry(ZipEntry);
        ZipStream.PutNextEntry(ZipEntry);19
 ZipStream.SetLevel(CompressionLevel);
        ZipStream.SetLevel(CompressionLevel);20
 byte[] buffer = new byte[BlockSize];
        byte[] buffer = new byte[BlockSize];21
 System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);
        System.Int32 size = StreamToZip.Read(buffer, 0, buffer.Length);22
 ZipStream.Write(buffer, 0, size);
        ZipStream.Write(buffer, 0, size);23
 try
        try24
 {
        {25
 while (size < StreamToZip.Length)
            while (size < StreamToZip.Length)26
 {
            {27
 int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);
                int sizeRead = StreamToZip.Read(buffer, 0, buffer.Length);28
 ZipStream.Write(buffer, 0, sizeRead);
                ZipStream.Write(buffer, 0, sizeRead);29
 size += sizeRead;
                size += sizeRead;30
 }
            }31
 }
        }32
 catch (System.Exception ex)
        catch (System.Exception ex)33
 {
        {34
 throw ex;
            throw ex;35
 }
        }36
 ZipStream.Finish();
        ZipStream.Finish();37
 ZipStream.Close();
        ZipStream.Close();38
 StreamToZip.Close();
        StreamToZip.Close();39
 }
    }40

41
 /// <summary>
    /// <summary>42
 /// 压缩目录
    /// 压缩目录43
 /// </summary>
    /// </summary>44
 /// <param name="args">数组(数组[0]: 要压缩的目录; 数组[1]: 压缩的文件名)</param>
    /// <param name="args">数组(数组[0]: 要压缩的目录; 数组[1]: 压缩的文件名)</param>45
 public static void ZipFileDictory(string[] args)
    public static void ZipFileDictory(string[] args)46
 {
    {47
 string[] filenames = Directory.GetFiles(args[0]);
        string[] filenames = Directory.GetFiles(args[0]);48

49
 Crc32 crc = new Crc32();
        Crc32 crc = new Crc32();50
 ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));
        ZipOutputStream s = new ZipOutputStream(File.Create(args[1]));            51
 s.SetLevel(6);
        s.SetLevel(6); 52
 foreach (string file in filenames)
        foreach (string file in filenames)53
 {
        {54
 //打开压缩文件
            //打开压缩文件55
 FileStream fs = File.OpenRead(file);
            FileStream fs = File.OpenRead(file);56

57
 byte[] buffer = new byte[fs.Length];
            byte[] buffer = new byte[fs.Length];58
 fs.Read(buffer, 0, buffer.Length);
            fs.Read(buffer, 0, buffer.Length);59
 ZipEntry entry = new ZipEntry(file);
            ZipEntry entry = new ZipEntry(file);60

61
 entry.DateTime = DateTime.Now;
            entry.DateTime = DateTime.Now;62
 
            63
 entry.Size = fs.Length;
            entry.Size = fs.Length;64
 fs.Close();
            fs.Close();65

66
 crc.Reset();
            crc.Reset();67
 crc.Update(buffer);
            crc.Update(buffer);68

69
 entry.Crc = crc.Value;
            entry.Crc = crc.Value;70

71
 s.PutNextEntry(entry);
            s.PutNextEntry(entry);72

73
 s.Write(buffer, 0, buffer.Length);
            s.Write(buffer, 0, buffer.Length);74

75
 }
        }76

77
 s.Finish();
        s.Finish();78
 s.Close();
        s.Close();79
 }
    }80

81
 /// <summary>
    /// <summary>82
 /// 压缩文件
    /// 压缩文件83
 /// </summary>
    /// </summary>84
 /// <param name="FileToZip">要进行压缩的文件名</param>
    /// <param name="FileToZip">要进行压缩的文件名</param>85
 /// <param name="ZipedFile">压缩后生成的压缩文件名</param>
    /// <param name="ZipedFile">压缩后生成的压缩文件名</param>86
 public static void ZipFile(string FileToZip, string ZipedFile)
    public static void ZipFile(string FileToZip, string ZipedFile)87
 {
    {88
 //如果文件没有找到,则报错
        //如果文件没有找到,则报错89
 if (!File.Exists(FileToZip))
        if (!File.Exists(FileToZip))90
 {
        {91
 throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
            throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");92
 }
        }            93
 FileStream fs = File.OpenRead(FileToZip);
        FileStream fs = File.OpenRead(FileToZip);94
 byte[] buffer = new byte[fs.Length];
        byte[] buffer = new byte[fs.Length];95
 fs.Read(buffer, 0, buffer.Length);
        fs.Read(buffer, 0, buffer.Length);96
 fs.Close();
        fs.Close();97

98
 FileStream ZipFile = File.Create(ZipedFile);
        FileStream ZipFile = File.Create(ZipedFile);99
 ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
        ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);100
 ZipEntry ZipEntry = new ZipEntry("ZippedFile");
        ZipEntry ZipEntry = new ZipEntry("ZippedFile");101
 ZipStream.PutNextEntry(ZipEntry);
        ZipStream.PutNextEntry(ZipEntry);102
 ZipStream.SetLevel(6);
        ZipStream.SetLevel(6);103
 
        104
 ZipStream.Write(buffer, 0, buffer.Length);
        ZipStream.Write(buffer, 0, buffer.Length);            105
 ZipStream.Finish();
        ZipStream.Finish();106
 ZipStream.Close();
        ZipStream.Close();107
 }
    }108
 }
}109

110
 /// <summary>
/// <summary>111
 ///  解压类
///  解压类112
 /// </summary>
/// </summary>113
 public class UnZipClass
public class UnZipClass114
 {
{115
 /// <summary>
    /// <summary>116
 /// 解压功能(解压压缩文件到指定目录)
    /// 解压功能(解压压缩文件到指定目录)117
 /// </summary>
    /// </summary>118
 /// <param name="args">待解压的文件</param>
    /// <param name="args">待解压的文件</param>119
 /// <param name="args">指定解压目标目录</param>
    /// <param name="args">指定解压目标目录</param>120
 public static void UnZip(string[] args)
    public static void UnZip(string[] args)121
 {
    {122
 ZipInputStream s = new ZipInputStream(File.OpenRead(@args[0].Trim()));
        ZipInputStream s = new ZipInputStream(File.OpenRead(@args[0].Trim()));            123
 ZipEntry theEntry;
        ZipEntry theEntry;124
 string directoryName = Path.GetDirectoryName(@args[1].Trim());
        string directoryName = Path.GetDirectoryName(@args[1].Trim());125
 
        126
 if (!Directory.Exists(@args[1].Trim()))
        if (!Directory.Exists(@args[1].Trim()))127
 {
        {128
 Directory.CreateDirectory(directoryName);
            Directory.CreateDirectory(directoryName);129
 }
        }130
 while ((theEntry = s.GetNextEntry()) != null)
        while ((theEntry = s.GetNextEntry()) != null)131
 {
        {132
 ;
            ;133
 string fileName = Path.GetFileName(theEntry.Name);
            string fileName = Path.GetFileName(theEntry.Name);134

135
 if (fileName != String.Empty)
            if (fileName != String.Empty)136
 {
            {            137
 FileStream streamWriter = File.Create(@args[1].Trim() + fileName);
                FileStream streamWriter = File.Create(@args[1].Trim() + fileName);138

139
 int size = 2048;
                int size = 2048;140
 byte[] data = new byte[2048];
                byte[] data = new byte[2048];141
 while (true)
                while (true)142
 {
                {143
 size = s.Read(data, 0, data.Length);
                    size = s.Read(data, 0, data.Length);144
 if (size > 0)
                    if (size > 0)145
 {
                    {146
 streamWriter.Write(data, 0, size);
                        streamWriter.Write(data, 0, size);147
 }
                    }148
 else
                    else149
 {
                    {150
 break;
                        break;151
 }
                    }152
 }
                }153

154
 streamWriter.Close();
                streamWriter.Close();155
 }
            }156
 }
        }157
 s.Close();
        s.Close();158
 }
    }159

2. 前台页面代码
 1 <body>
      <body>
2 <form id="form1" runat="server">
    <form id="form1" runat="server">
3 <div>
    <div>
4  <asp:Label ID="Label1" runat="server" BackColor="#C0C0FF" Font-Size="XX-Large"
         <asp:Label ID="Label1" runat="server" BackColor="#C0C0FF" Font-Size="XX-Large"
5 Height="44px" Text="压缩文件/文件夹示例" Width="366px"></asp:Label>
            Height="44px" Text="压缩文件/文件夹示例" Width="366px"></asp:Label>
6 <asp:Panel ID="Panel1" runat="server" Height="1px" Width="369px" BackColor="#FFFFC0">
        <asp:Panel ID="Panel1" runat="server" Height="1px" Width="369px" BackColor="#FFFFC0">
7 <table width="100%" height="100%">
            <table width="100%" height="100%">
8 <tr>
                <tr>
9 <td style="width: 3px" valign="top">
                    <td style="width: 3px" valign="top">
10 <asp:Label ID="lbDisplay" runat="server" Text="压缩目录(from/to):" Width="153px"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <asp:Label ID="lbDisplay" runat="server" Text="压缩目录(from/to):" Width="153px"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
11 <br />
            <br />
12 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
13  <br />
             <br />
14 <asp:Button ID="btZipDictory" runat="server" OnClick="btZipDictory_Click" Text="压缩目录" /><br />
            <asp:Button ID="btZipDictory" runat="server" OnClick="btZipDictory_Click" Text="压缩目录" /><br />
15 </td>
                    </td>
16 <td style="width: 4px" valign="middle">
                    <td style="width: 4px" valign="middle">
17 <asp:Label ID="Label2" runat="server" Text="解压目录(from/to):" Width="154px"></asp:Label>
                        <asp:Label ID="Label2" runat="server" Text="解压目录(from/to):" Width="154px"></asp:Label>
18 <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
19 <br />
                        <br />
20 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
21  <br />
                         <br />
22 <asp:Button ID="btUnZipDictory" runat="server" Text="解压目录" OnClick="btUnZipDictory_Click" /><br />
                        <asp:Button ID="btUnZipDictory" runat="server" Text="解压目录" OnClick="btUnZipDictory_Click" /><br />
23 </td>
                    </td>              
24 </tr>
                </tr>
25 <tr>
                <tr>
26 <td style="width: 3px; height: 150px" valign="top">
                    <td style="width: 3px; height: 150px" valign="top">
27 <asp:Label ID="Label3" runat="server" Text="压缩文件(from/to):" Width="153px"></asp:Label>
                        <asp:Label ID="Label3" runat="server" Text="压缩文件(from/to):" Width="153px"></asp:Label>
28 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
29 <br />
                        <br />
30 <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
31  <br />
                         <br />
32 <asp:Button ID="btZipFile" runat="server" Text="压缩文件" OnClick="btZipFile_Click" /><br />
                        <asp:Button ID="btZipFile" runat="server" Text="压缩文件" OnClick="btZipFile_Click" /><br />
33 </td>
                    </td>
34 <td style="width: 4px; height: 150px" valign="top">
                    <td style="width: 4px; height: 150px" valign="top">
35 <asp:Label ID="Label4" runat="server" Text="解压文件(from/to):" Width="154px"></asp:Label>
                        <asp:Label ID="Label4" runat="server" Text="解压文件(from/to):" Width="154px"></asp:Label>
36 <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
37 <br />
                        <br />
38 <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
39  <br />
                         <br />
40 <asp:Button ID="btUnZipFile" runat="server" Text="解压文件" OnClick="btUnZipFile_Click" /><br />
                        <asp:Button ID="btUnZipFile" runat="server" Text="解压文件" OnClick="btUnZipFile_Click" /><br />
41 </td>
                    </td>
42 
             
43 </tr>
                </tr>
44 
     
45 </table>
            </table>
46 <asp:Label ID="lbMessage" runat="server" Width="368px"></asp:Label><br />
            <asp:Label ID="lbMessage" runat="server" Width="368px"></asp:Label><br />
47 <br />
            <br />
48 </asp:Panel>
        </asp:Panel>
49 
    
50 </div>
    </div>
51 </form>
    </form>
52 </body>
</body>
53
 <body>
      <body>2
 <form id="form1" runat="server">
    <form id="form1" runat="server">3
 <div>
    <div>4
  <asp:Label ID="Label1" runat="server" BackColor="#C0C0FF" Font-Size="XX-Large"
         <asp:Label ID="Label1" runat="server" BackColor="#C0C0FF" Font-Size="XX-Large"5
 Height="44px" Text="压缩文件/文件夹示例" Width="366px"></asp:Label>
            Height="44px" Text="压缩文件/文件夹示例" Width="366px"></asp:Label>6
 <asp:Panel ID="Panel1" runat="server" Height="1px" Width="369px" BackColor="#FFFFC0">
        <asp:Panel ID="Panel1" runat="server" Height="1px" Width="369px" BackColor="#FFFFC0">7
 <table width="100%" height="100%">
            <table width="100%" height="100%">8
 <tr>
                <tr>9
 <td style="width: 3px" valign="top">
                    <td style="width: 3px" valign="top">10
 <asp:Label ID="lbDisplay" runat="server" Text="压缩目录(from/to):" Width="153px"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <asp:Label ID="lbDisplay" runat="server" Text="压缩目录(from/to):" Width="153px"></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>11
 <br />
            <br />12
 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>13
  <br />
             <br />14
 <asp:Button ID="btZipDictory" runat="server" OnClick="btZipDictory_Click" Text="压缩目录" /><br />
            <asp:Button ID="btZipDictory" runat="server" OnClick="btZipDictory_Click" Text="压缩目录" /><br />15
 </td>
                    </td>16
 <td style="width: 4px" valign="middle">
                    <td style="width: 4px" valign="middle">17
 <asp:Label ID="Label2" runat="server" Text="解压目录(from/to):" Width="154px"></asp:Label>
                        <asp:Label ID="Label2" runat="server" Text="解压目录(from/to):" Width="154px"></asp:Label>18
 <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>19
 <br />
                        <br />20
 <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>21
  <br />
                         <br />22
 <asp:Button ID="btUnZipDictory" runat="server" Text="解压目录" OnClick="btUnZipDictory_Click" /><br />
                        <asp:Button ID="btUnZipDictory" runat="server" Text="解压目录" OnClick="btUnZipDictory_Click" /><br />23
 </td>
                    </td>              24
 </tr>
                </tr>25
 <tr>
                <tr>26
 <td style="width: 3px; height: 150px" valign="top">
                    <td style="width: 3px; height: 150px" valign="top">27
 <asp:Label ID="Label3" runat="server" Text="压缩文件(from/to):" Width="153px"></asp:Label>
                        <asp:Label ID="Label3" runat="server" Text="压缩文件(from/to):" Width="153px"></asp:Label>28
 <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>29
 <br />
                        <br />30
 <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>31
  <br />
                         <br />32
 <asp:Button ID="btZipFile" runat="server" Text="压缩文件" OnClick="btZipFile_Click" /><br />
                        <asp:Button ID="btZipFile" runat="server" Text="压缩文件" OnClick="btZipFile_Click" /><br />33
 </td>
                    </td>34
 <td style="width: 4px; height: 150px" valign="top">
                    <td style="width: 4px; height: 150px" valign="top">35
 <asp:Label ID="Label4" runat="server" Text="解压文件(from/to):" Width="154px"></asp:Label>
                        <asp:Label ID="Label4" runat="server" Text="解压文件(from/to):" Width="154px"></asp:Label>36
 <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>37
 <br />
                        <br />38
 <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
                        <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>39
  <br />
                         <br />40
 <asp:Button ID="btUnZipFile" runat="server" Text="解压文件" OnClick="btUnZipFile_Click" /><br />
                        <asp:Button ID="btUnZipFile" runat="server" Text="解压文件" OnClick="btUnZipFile_Click" /><br />41
 </td>
                    </td>42
 
             43
 </tr>
                </tr>44
 
     45
 </table>
            </table>46
 <asp:Label ID="lbMessage" runat="server" Width="368px"></asp:Label><br />
            <asp:Label ID="lbMessage" runat="server" Width="368px"></asp:Label><br />47
 <br />
            <br />48
 </asp:Panel>
        </asp:Panel>49
 
    50
 </div>
    </div>51
 </form>
    </form>52
 </body>
</body>53

3. 后台页面代码
 1 public partial class _Default : System.Web.UI.Page
public partial class _Default : System.Web.UI.Page 
2 {
{
3 protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e)
4 {
    {
5
6 }
    }
7 protected void btZipDictory_Click(object sender, EventArgs e)
    protected void btZipDictory_Click(object sender, EventArgs e)
8 {
    {
9 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];
10 FilePathS[0] = TextBox1.Text.Trim();  //待压缩的文件目录
        FilePathS[0] = TextBox1.Text.Trim();  //待压缩的文件目录
11 FilePathS[1] = TextBox2.Text.Trim();  //生成的目标文件
        FilePathS[1] = TextBox2.Text.Trim();  //生成的目标文件        
12 ZipClass.ZipFileDictory(FilePathS);
        ZipClass.ZipFileDictory(FilePathS);
13 }
    }
14 protected void btUnZipDictory_Click(object sender, EventArgs e)
    protected void btUnZipDictory_Click(object sender, EventArgs e)
15 {
    {
16 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];
17 FilePathS[0] = TextBox3.Text.Trim();  //待解压的文件
        FilePathS[0] = TextBox3.Text.Trim();  //待解压的文件
18 FilePathS[1] = TextBox4.Text.Trim();  //解压目标存放目录
        FilePathS[1] = TextBox4.Text.Trim();  //解压目标存放目录
19 UnZipClass.UnZip(FilePathS);
        UnZipClass.UnZip(FilePathS);
20 }
    }
21 protected void btZipFile_Click(object sender, EventArgs e)
    protected void btZipFile_Click(object sender, EventArgs e)
22 {
    {
23 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];
24 FilePathS[0] = TextBox5.Text.Trim();  //待压缩的文件
        FilePathS[0] = TextBox5.Text.Trim();  //待压缩的文件
25 FilePathS[1] = TextBox6.Text.Trim();  //生成的压缩文件名
        FilePathS[1] = TextBox6.Text.Trim();  //生成的压缩文件名
26 ZipClass.ZipFile(FilePathS[0], FilePathS[1]);
        ZipClass.ZipFile(FilePathS[0], FilePathS[1]);
27
28 }
    }
29 protected void btUnZipFile_Click(object sender, EventArgs e)
    protected void btUnZipFile_Click(object sender, EventArgs e)
30 {
    {
31 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];
32 FilePathS[0] = TextBox7.Text.Trim();  //待解压的文件
        FilePathS[0] = TextBox7.Text.Trim();  //待解压的文件
33 FilePathS[1] = TextBox8.Text.Trim();  //解压目标存放目录
        FilePathS[1] = TextBox8.Text.Trim();  //解压目标存放目录
34 UnZipClass.UnZip(FilePathS);
        UnZipClass.UnZip(FilePathS);
35 }
    }
36 }
}
37
 public partial class _Default : System.Web.UI.Page
public partial class _Default : System.Web.UI.Page 2
 {
{3
 protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e)4
 {
    {5

6
 }
    }7
 protected void btZipDictory_Click(object sender, EventArgs e)
    protected void btZipDictory_Click(object sender, EventArgs e)8
 {
    {9
 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];10
 FilePathS[0] = TextBox1.Text.Trim();  //待压缩的文件目录
        FilePathS[0] = TextBox1.Text.Trim();  //待压缩的文件目录11
 FilePathS[1] = TextBox2.Text.Trim();  //生成的目标文件
        FilePathS[1] = TextBox2.Text.Trim();  //生成的目标文件        12
 ZipClass.ZipFileDictory(FilePathS);
        ZipClass.ZipFileDictory(FilePathS);13
 }
    }14
 protected void btUnZipDictory_Click(object sender, EventArgs e)
    protected void btUnZipDictory_Click(object sender, EventArgs e)15
 {
    {16
 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];17
 FilePathS[0] = TextBox3.Text.Trim();  //待解压的文件
        FilePathS[0] = TextBox3.Text.Trim();  //待解压的文件18
 FilePathS[1] = TextBox4.Text.Trim();  //解压目标存放目录
        FilePathS[1] = TextBox4.Text.Trim();  //解压目标存放目录19
 UnZipClass.UnZip(FilePathS);
        UnZipClass.UnZip(FilePathS);20
 }
    }21
 protected void btZipFile_Click(object sender, EventArgs e)
    protected void btZipFile_Click(object sender, EventArgs e)22
 {
    {23
 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];24
 FilePathS[0] = TextBox5.Text.Trim();  //待压缩的文件
        FilePathS[0] = TextBox5.Text.Trim();  //待压缩的文件25
 FilePathS[1] = TextBox6.Text.Trim();  //生成的压缩文件名
        FilePathS[1] = TextBox6.Text.Trim();  //生成的压缩文件名26
 ZipClass.ZipFile(FilePathS[0], FilePathS[1]);
        ZipClass.ZipFile(FilePathS[0], FilePathS[1]);27

28
 }
    }29
 protected void btUnZipFile_Click(object sender, EventArgs e)
    protected void btUnZipFile_Click(object sender, EventArgs e)30
 {
    {31
 string[] FilePathS = new string[2];
        string[] FilePathS = new string[2];32
 FilePathS[0] = TextBox7.Text.Trim();  //待解压的文件
        FilePathS[0] = TextBox7.Text.Trim();  //待解压的文件33
 FilePathS[1] = TextBox8.Text.Trim();  //解压目标存放目录
        FilePathS[1] = TextBox8.Text.Trim();  //解压目标存放目录34
 UnZipClass.UnZip(FilePathS);
        UnZipClass.UnZip(FilePathS);35
 }
    }36
 }
}37

(四). 示例代码下载
 
                    
                 
				  
 
        

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号