ASP.NET extract the zip file and place specified in the path file decompression

This link: https://www.cnblogs.com/yifeixue/p/11769905.html

I have been an effective pro-test (* ^ ▽ ^ *)

Ado, directly on the code:

. 1          ///  <Summary> 
2          /// extracting file
 . 3          ///  </ Summary> 
. 4          /// <param name = "ZipPath"> to be decompressed file </ param> 
. 5          ///  <param name = "path"> path of the file after decompression </ param> 
. 6          public  String UnzipTheFiles ( String TorepotFiles, String reportPath)
 . 7          {
 . 8              String Error = null ;
 . 9              ActionRetDto ActionRet = new 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         }

This link: https://www.cnblogs.com/yifeixue/p/11769905.html

Guess you like

Origin www.cnblogs.com/yifeixue/p/11769905.html