ASP.NET解压zip文件,并将解压后的文件放到指定路径中

本文链接: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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值