SharpZipLib 压缩ZIP导出
生活随笔
收集整理的這篇文章主要介紹了
SharpZipLib 压缩ZIP导出
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 var uploadSectionDir = Path.Combine("Upload", "QQ", DateTime.Now.ToString("yyyyMMdd"));
2 string uploadDir = Path.Combine(HttpRuntime.AppDomainAppPath, uploadSectionDir);
3 if (!Directory.Exists(uploadDir))
4 {
5 Directory.CreateDirectory(uploadDir);
6 }
7 string fileName ="test.zip";
8 string filePath = Path.Combine(uploadDir, fileName);
9
10 //生成的壓縮文件為test.zip
11 using (FileStream fsOut = System.IO.File.Create(filePath))
12 {
13 //ZipOutputStream類的構造函數需要一個流,文件流、內存流都可以,壓縮后的內容會寫入到這個流中。
14 using (ZipOutputStream zipStream = new ZipOutputStream(fsOut))
15 {
16 MemoryStream ws = new AirBillBLL().ExportToExcel(ladingNoList);
17 string entryName = string.Concat(string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now), ".xls");
18 ZipEntry newEntry = new ZipEntry(entryName);
19 newEntry.DateTime = DateTime.Now;
20 newEntry.Size = ws.Length;
21
22 //把壓縮項的信息添加到ZipOutputStream中。
23 zipStream.PutNextEntry(newEntry);
24 byte[] buffer = new byte[4096];
25 //把需要壓縮文件以文件流的方式復制到ZipOutputStream中。
26
27 StreamUtils.Copy(ws, zipStream, buffer);
28
29 zipStream.CloseEntry();
30 zipStream.IsStreamOwner = false;
31 zipStream.Finish();
32 zipStream.Close();
33 }
34 }
35 return File(filePath, "application/x-zip-compressed", string.Concat(string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now), ".zip"));
35 return File(filePath, "application/x-zip-compressed", string.Concat(string.Format("{0:yyyyMMddHHmmssffff}", DateTime.Now), ".zip"));
?
轉載于:https://www.cnblogs.com/LiuFengH/p/9862309.html
總結
以上是生活随笔為你收集整理的SharpZipLib 压缩ZIP导出的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 本地连不上远程mysql数据库(2)
- 下一篇: UI进阶--Quartz2D和触摸事件的