本文链接:https://www.cnblogs.com/yifeixue/p/11769905.html

本人已亲测有效(*^▽^*)

废话不多说了,直接上代码:

 1         /// <summary>
 2         /// 解压文件
 3         /// </summary>
 4         ///<param name = "ZipPath" > 需要被解压的文件 </ param >
 5         /// <param name="Path">解压后文件的路径</param>
 6         public string UnzipTheFiles(string TorepotFiles, string reportPath)
 7         {
 8             string Error = null;
 9             ActionRetDto ActionRet = new ActionRetDto();
10
11             ZipInputStream s = new ZipInputStream(File.OpenRead(TorepotFiles));
12
13             ZipEntry theEntry;
14             try
15             {
16                 while ((theEntry = s.GetNextEntry()) != null)
17                 {
18                     string fileName = System.IO.Path.GetFileName(theEntry.Name);
19                     //生成解压目录
20                     Directory.CreateDirectory(reportPath);
21
22                     if (fileName != String.Empty)
23                     {
24                         //解压文件
25                         FileStream streamWriter = File.Create(reportPath + fileName);
26
27                         int size = 2048;
28                         byte[] data = new byte[2048];
29                         while (true)
30                         {
31                             size = s.Read(data, 0, data.Length);
32                             if (size > 0)
33                             {
34                                 streamWriter.Write(data, 0, size);
35                             }
36                             else
37                             {
38
39                                 streamWriter.Close();
40                                 streamWriter.Dispose();
41                                 break;
42                             }
43                         }
44
45                         streamWriter.Close();
46                         streamWriter.Dispose();
47                     }
48                 }
49             }
50             catch (Exception ex)
51             {
52                 Error = ErrorUtil.GetError(ex);
53                 ActionRet.Error = Error;
54                 throw ex;
55             }
56             finally
57             {
58                 s.Close();
59                 s.Dispose();
60             }
61             return reportPath;
62         }

本文链接:https://www.cnblogs.com/yifeixue/p/11769905.html

12-31 14:32