<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      RDIFramework.NET ━ .NET快速信息化系統(tǒng)開發(fā)框架 V3.2 新增解壓縮工具類ZipHelper

        在項目對文件進行解壓縮是非常常用的功能,對文件進行壓縮存儲或傳輸可以節(jié)省流量與空間。壓縮文件的格式與方法都比較多,比較常用的國際標(biāo)準(zhǔn)是zip格式。壓縮與解壓縮的方法也很多,在.NET 2.0開始,在System.IO.Compression中微軟已經(jīng)給我們提供了解壓縮的方法GZipStream。對于GZipStream的使用以及優(yōu)缺點網(wǎng)上已經(jīng)有非常多的文章,本文主要講的是利用三方開源組件ICSharpCode.SharpZipLib進行文件的解壓縮。

        SharpZipLib地址:http://www.icsharpcode.net/OpenSource/SharpZipLib/Default.aspx

        SharpZipLib是一個使用C#編寫的Zip操作類庫,是一個開源的C#壓縮解壓庫,應(yīng)用非常廣泛。在VB.NET、C#或其他的.NET語言中都可以使用它創(chuàng)建Zip文件、并進行讀取和更新等操作。SharpZipLib是一個完全由c#編寫的Zip, GZip, Tar and BZip2 library,可以方便地支持這幾種格式的壓縮解壓縮。SharpZipLib目前的版本為0.86,我們可以直接從上面提供的網(wǎng)站下載dll文件再添加到項目引用中,也可以通過VS提供的包管理工具NuGet把SharpZipLib添加到項目中。NuGet能更方便地把一些dll和文件添加到項目中,而不需要從文件中復(fù)制拷貝,推薦使用。使用NuGet添加SharpZipLib到項目中的方法如下圖所示,在我們需要SharpZipLib的項目中右鍵單擊“引用”,在彈出的快捷菜單中選擇“管理NuGet程序包(N)…”。

       

        在打開的“管理NuGet程序包”對話框,搜索SharpZipLib找到后單擊安裝即可。

        引用SharpZipLib到項目中后,我們就可以編寫相應(yīng)的加壓縮方法,下面將對常用的方法一一分享。

        在使用前必須先添加引用如下:

          using ICSharpCode.SharpZipLib.Checksums;
          using ICSharpCode.SharpZipLib.Zip;  

        一、壓縮文件夾 

           /// <summary>
              /// 壓縮文件夾
              /// </summary>
              /// <param name="dirToZip"></param>
              /// <param name="zipedFileName"></param>
              /// <param name="compressionLevel">壓縮率0(無壓縮)9(壓縮率最高)</param>
              public static void ZipDir(string dirToZip, string zipedFileName, int compressionLevel = 9)
              {
                  if (Path.GetExtension(zipedFileName) != ".zip")
                  {
                      zipedFileName = zipedFileName + ".zip";
                  }
                  using (var zipoutputstream = new ZipOutputStream(File.Create(zipedFileName)))
                  {
                      zipoutputstream.SetLevel(compressionLevel);
                      Crc32 crc = new Crc32();
                      Hashtable fileList = GetAllFies(dirToZip);
                      foreach (DictionaryEntry item in fileList)
                      {
                          FileStream fs = new FileStream(item.Key.ToString(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                          byte[] buffer = new byte[fs.Length];
                          fs.Read(buffer, 0, buffer.Length);;
                          ZipEntry entry = new ZipEntry(Path.GetFileName(item.Key.ToString()))
                          {
                              DateTime = (DateTime)item.Value,
                              Size = fs.Length
                          };
                          fs.Close();
                          crc.Reset();
                          crc.Update(buffer);
                          entry.Crc = crc.Value;
                          zipoutputstream.PutNextEntry(entry);
                          zipoutputstream.Write(buffer, 0, buffer.Length);
                      }
                  }
              }
      

        二、解壓文件夾

           /// <summary>  
              /// 功能:解壓zip格式的文件。  
              /// </summary>  
              /// <param name="zipFilePath">壓縮文件路徑</param>  
              /// <param name="unZipDir">解壓文件存放路徑,為空時默認(rèn)與壓縮文件同一級目錄下,跟壓縮文件同名的文件夾</param>  
              /// <returns>解壓是否成功</returns>  
              public static void UnZip(string zipFilePath, string unZipDir)
              {
                  if (zipFilePath == string.Empty)
                  {
                      throw new Exception("壓縮文件不能為空!");
                  }
                  if (!File.Exists(zipFilePath))
                  {
                      throw new FileNotFoundException("壓縮文件不存在!");
                  }
                  //解壓文件夾為空時默認(rèn)與壓縮文件同一級目錄下,跟壓縮文件同名的文件夾  
                  if (unZipDir == string.Empty)
                      unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
                  if (!unZipDir.EndsWith("/"))
                      unZipDir += "/";
                  if (!Directory.Exists(unZipDir))
                      Directory.CreateDirectory(unZipDir);
      
                  using (var s = new ZipInputStream(File.OpenRead(zipFilePath)))
                  {
      
                      ZipEntry theEntry;
                      while ((theEntry = s.GetNextEntry()) != null)
                      {
                          string directoryName = Path.GetDirectoryName(theEntry.Name);
                          string fileName = Path.GetFileName(theEntry.Name);
                          if (!string.IsNullOrEmpty(directoryName))
                          {
                              Directory.CreateDirectory(unZipDir + directoryName);
                          }
                          if (directoryName != null && !directoryName.EndsWith("/"))
                          {
                          }
                          if (fileName != String.Empty)
                          {
                              using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))
                              {
      
                                  int size;
                                  byte[] data = new byte[2048];
                                  while (true)
                                  {
                                      size = s.Read(data, 0, data.Length);
                                      if (size > 0)
                                      {
                                          streamWriter.Write(data, 0, size);
                                      }
                                      else
                                      {
                                          break;
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
      

        三、壓縮單個文件

            /// <summary> 
              /// 壓縮單個文件 
              /// </summary> 
              /// <param name="fileToZip">要進行壓縮的文件名,全路徑</param> 
              /// <param name="zipedFile">壓縮后生成的壓縮文件名,全路徑</param> 
              public static void ZipFile(string fileToZip, string zipedFile)
              {
                  // 如果文件沒有找到,則報錯 
                  if (!File.Exists(fileToZip))
                  {
                      throw new FileNotFoundException("指定要壓縮的文件: " + fileToZip + " 不存在!");
                  }
                  using (FileStream fileStream = File.OpenRead(fileToZip))
                  {
                      byte[] buffer = new byte[fileStream.Length];
                      fileStream.Read(buffer, 0, buffer.Length);
                      fileStream.Close();
                      using (FileStream zipFile = File.Create(zipedFile))
                      {
                          using (ZipOutputStream zipOutputStream = new ZipOutputStream(zipFile))
                          {
                              // string fileName = fileToZip.Substring(fileToZip.LastIndexOf("\\") + 1);
                              string fileName = Path.GetFileName(fileToZip);
                              var zipEntry = new ZipEntry(fileName)
                              {
                                  DateTime = DateTime.Now,
                                  IsUnicodeText = true
                              };
                              zipOutputStream.PutNextEntry(zipEntry);
                              zipOutputStream.SetLevel(5);
                              zipOutputStream.Write(buffer, 0, buffer.Length);
                              zipOutputStream.Finish();
                              zipOutputStream.Close();
                          }
                      }
                  }
              }
      

        三、壓縮單個文件

           /// <summary>
              /// 壓縮多個目錄或文件
              /// </summary>
              /// <param name="folderOrFileList">待壓縮的文件夾或者文件,全路徑格式,是一個集合</param>
              /// <param name="zipedFile">壓縮后的文件名,全路徑格式</param>
              /// <param name="password">壓宿密碼</param>
              /// <returns></returns>
              public static bool ZipManyFilesOrDictorys(IEnumerable<string> folderOrFileList, string zipedFile, string password)
              {
                  bool res = true;
                  using (var s = new ZipOutputStream(File.Create(zipedFile)))
                  {
                      s.SetLevel(6);
                      if (!string.IsNullOrEmpty(password))
                      {
                          s.Password = password;
                      }
                      foreach (string fileOrDir in folderOrFileList)
                      {
                          //是文件夾
                          if (Directory.Exists(fileOrDir))
                          {
                              res = ZipFileDictory(fileOrDir, s, "");
                          }
                          else
                          {
                              //文件
                              res = ZipFileWithStream(fileOrDir, s);
                          }
                      }
                      s.Finish();
                      s.Close();
                      return res;
                  }
              }
      

        五、遞歸壓縮文件夾

           /// <summary>
              /// 遞歸壓縮文件夾方法
              /// </summary>
              /// <param name="folderToZip"></param>
              /// <param name="s"></param>
              /// <param name="parentFolderName"></param>
              private static bool ZipFileDictory(string folderToZip, ZipOutputStream s, string parentFolderName)
              {
                  bool res = true;
                  ZipEntry entry = null;
                  FileStream fs = null;
                  Crc32 crc = new Crc32();
                  try
                  {
                      //創(chuàng)建當(dāng)前文件夾
                      entry = new ZipEntry(Path.Combine(parentFolderName, Path.GetFileName(folderToZip) + "/")); //加上 “/” 才會當(dāng)成是文件夾創(chuàng)建
                      s.PutNextEntry(entry);
                      s.Flush();
                      //先壓縮文件,再遞歸壓縮文件夾
                      var filenames = Directory.GetFiles(folderToZip);
                      foreach (string file in filenames)
                      {
                          //打開壓縮文件
                          fs = File.OpenRead(file);
                          byte[] buffer = new byte[fs.Length];
                          fs.Read(buffer, 0, buffer.Length);
                          entry = new ZipEntry(Path.Combine(parentFolderName, Path.GetFileName(folderToZip) + "/" + Path.GetFileName(file)));
                          entry.DateTime = DateTime.Now;
                          entry.Size = fs.Length;
                          fs.Close();
                          crc.Reset();
                          crc.Update(buffer);
                          entry.Crc = crc.Value;
                          s.PutNextEntry(entry);
                          s.Write(buffer, 0, buffer.Length);
                      }
                  }
                  catch
                  {
                      res = false;
                  }
                  finally
                  {
                      if (fs != null)
                      {
                          fs.Close();
                      }
                      if (entry != null)
                      {
                      }
                      GC.Collect();
                      GC.Collect(1);
                  }
                  var folders = Directory.GetDirectories(folderToZip);
                  foreach (string folder in folders)
                  {
                      if (!ZipFileDictory(folder, s, Path.Combine(parentFolderName, Path.GetFileName(folderToZip))))
                      {
                          return false;
                      }
                  }
                  return res;
              }
      

        利用ICSharpCode.SharpZipLib解壓縮輔助類全部代碼如下:

      using System;
      using System.Collections;
      using System.Collections.Generic;
      using System.IO;
      
      namespace RDIFramework.Utilities
      {
          using ICSharpCode.SharpZipLib.Checksums;
          using ICSharpCode.SharpZipLib.Zip;
      
          /// <summary>
          /// ZipHelper.cs
          /// Zip解壓縮幫助類
          ///
          /// 修改紀(jì)錄
          ///     
          ///     2017-03-05 EricHu   創(chuàng)建。
          /// 
          /// 版本:1.0
          ///
          /// <author>
          ///        <name>EricHu</name>
          ///        <date>2017-03-05</date>
          /// </author>
          /// </summary>
          public class ZipHelper
          {
              /// <summary>
              /// 壓縮文件夾
              /// </summary>
              /// <param name="dirToZip"></param>
              /// <param name="zipedFileName"></param>
              /// <param name="compressionLevel">壓縮率0(無壓縮)9(壓縮率最高)</param>
              public static void ZipDir(string dirToZip, string zipedFileName, int compressionLevel = 9)
              {
                  if (Path.GetExtension(zipedFileName) != ".zip")
                  {
                      zipedFileName = zipedFileName + ".zip";
                  }
                  using (var zipoutputstream = new ZipOutputStream(File.Create(zipedFileName)))
                  {
                      zipoutputstream.SetLevel(compressionLevel);
                      Crc32 crc = new Crc32();
                      Hashtable fileList = GetAllFies(dirToZip);
                      foreach (DictionaryEntry item in fileList)
                      {
                          FileStream fs = new FileStream(item.Key.ToString(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                          byte[] buffer = new byte[fs.Length];
                          fs.Read(buffer, 0, buffer.Length);;
                          ZipEntry entry = new ZipEntry(Path.GetFileName(item.Key.ToString()))
                          {
                              DateTime = (DateTime)item.Value,
                              Size = fs.Length
                          };
                          fs.Close();
                          crc.Reset();
                          crc.Update(buffer);
                          entry.Crc = crc.Value;
                          zipoutputstream.PutNextEntry(entry);
                          zipoutputstream.Write(buffer, 0, buffer.Length);
                      }
                  }
              }
      
              /// <summary>  
              /// 獲取所有文件  
              /// </summary>  
              /// <returns></returns>  
              public static Hashtable GetAllFies(string dir)
              {
                  Hashtable filesList = new Hashtable();
                  DirectoryInfo fileDire = new DirectoryInfo(dir);
                  if (!fileDire.Exists)
                  {
                      throw new FileNotFoundException("目錄:" + fileDire.FullName + "沒有找到!");
                  }
      
                  GetAllDirFiles(fileDire, filesList);
                  GetAllDirsFiles(fileDire.GetDirectories(), filesList);
                  return filesList;
              }
      
              /// <summary>  
              /// 獲取一個文件夾下的所有文件夾里的文件  
              /// </summary>  
              /// <param name="dirs"></param>  
              /// <param name="filesList"></param>  
              public static void GetAllDirsFiles(IEnumerable<DirectoryInfo> dirs, Hashtable filesList)
              {
                  foreach (DirectoryInfo dir in dirs)
                  {
                      foreach (FileInfo file in dir.GetFiles("*.*"))
                      {
                          filesList.Add(file.FullName, file.LastWriteTime);
                      }
                      GetAllDirsFiles(dir.GetDirectories(), filesList);
                  }
              }
      
              /// <summary>  
              /// 獲取一個文件夾下的文件  
              /// </summary>  
              /// <param name="dir">目錄名稱</param>
              /// <param name="filesList">文件列表HastTable</param>  
              public static void GetAllDirFiles(DirectoryInfo dir, Hashtable filesList)
              {
                  foreach (FileInfo file in dir.GetFiles("*.*"))
                  {
                      filesList.Add(file.FullName, file.LastWriteTime);
                  }
              }
      
              /// <summary>  
              /// 功能:解壓zip格式的文件。  
              /// </summary>  
              /// <param name="zipFilePath">壓縮文件路徑</param>  
              /// <param name="unZipDir">解壓文件存放路徑,為空時默認(rèn)與壓縮文件同一級目錄下,跟壓縮文件同名的文件夾</param>  
              /// <returns>解壓是否成功</returns>  
              public static void UnZip(string zipFilePath, string unZipDir)
              {
                  if (zipFilePath == string.Empty)
                  {
                      throw new Exception("壓縮文件不能為空!");
                  }
                  if (!File.Exists(zipFilePath))
                  {
                      throw new FileNotFoundException("壓縮文件不存在!");
                  }
                  //解壓文件夾為空時默認(rèn)與壓縮文件同一級目錄下,跟壓縮文件同名的文件夾  
                  if (unZipDir == string.Empty)
                      unZipDir = zipFilePath.Replace(Path.GetFileName(zipFilePath), Path.GetFileNameWithoutExtension(zipFilePath));
                  if (!unZipDir.EndsWith("/"))
                      unZipDir += "/";
                  if (!Directory.Exists(unZipDir))
                      Directory.CreateDirectory(unZipDir);
      
                  using (var s = new ZipInputStream(File.OpenRead(zipFilePath)))
                  {
      
                      ZipEntry theEntry;
                      while ((theEntry = s.GetNextEntry()) != null)
                      {
                          string directoryName = Path.GetDirectoryName(theEntry.Name);
                          string fileName = Path.GetFileName(theEntry.Name);
                          if (!string.IsNullOrEmpty(directoryName))
                          {
                              Directory.CreateDirectory(unZipDir + directoryName);
                          }
                          if (directoryName != null && !directoryName.EndsWith("/"))
                          {
                          }
                          if (fileName != String.Empty)
                          {
                              using (FileStream streamWriter = File.Create(unZipDir + theEntry.Name))
                              {
      
                                  int size;
                                  byte[] data = new byte[2048];
                                  while (true)
                                  {
                                      size = s.Read(data, 0, data.Length);
                                      if (size > 0)
                                      {
                                          streamWriter.Write(data, 0, size);
                                      }
                                      else
                                      {
                                          break;
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
      
              /// <summary>
              /// 壓縮單個文件
              /// </summary>
              /// <param name="filePath">被壓縮的文件名稱(包含文件路徑),文件的全路徑</param>
              /// <param name="zipedFileName">壓縮后的文件名稱(包含文件路徑),保存的文件名稱</param>
              /// <param name="compressionLevel">壓縮率0(無壓縮)到 9(壓縮率最高)</param>
              public static void ZipFile(string filePath, string zipedFileName, int compressionLevel = 9)
              {
                  // 如果文件沒有找到,則報錯 
                  if (!File.Exists(filePath))
                  {
                      throw new FileNotFoundException("文件:" + filePath + "沒有找到!");
                  }
                  // 如果壓縮后名字為空就默認(rèn)使用源文件名稱作為壓縮文件名稱
                  if (string.IsNullOrEmpty(zipedFileName))
                  {
                      string oldValue = Path.GetFileName(filePath);
                      if (oldValue != null)
                      {
                          zipedFileName = filePath.Replace(oldValue, "") + Path.GetFileNameWithoutExtension(filePath) + ".zip";
                      }
                  }
                  // 如果壓縮后的文件名稱后綴名不是zip,就是加上zip,防止是一個亂碼文件
                  if (Path.GetExtension(zipedFileName) != ".zip")
                  {
                      zipedFileName = zipedFileName + ".zip";
                  }
                  // 如果指定位置目錄不存在,創(chuàng)建該目錄  C:\Users\yhl\Desktop\大漢三通
                  string zipedDir = zipedFileName.Substring(0, zipedFileName.LastIndexOf("\\", StringComparison.Ordinal));
                  if (!Directory.Exists(zipedDir))
                  {
                      Directory.CreateDirectory(zipedDir);
                  }
                  // 被壓縮文件名稱
                  string filename = filePath.Substring(filePath.LastIndexOf("\\", StringComparison.Ordinal) + 1);
                  var streamToZip = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                  var zipFile = File.Create(zipedFileName);
                  var zipStream = new ZipOutputStream(zipFile);
                  var zipEntry = new ZipEntry(filename);
                  zipStream.PutNextEntry(zipEntry);
                  zipStream.SetLevel(compressionLevel);
                  var buffer = new byte[2048];
                  Int32 size = streamToZip.Read(buffer, 0, buffer.Length);
                  zipStream.Write(buffer, 0, size);
                  try
                  {
                      while (size < streamToZip.Length)
                      {
                          int sizeRead = streamToZip.Read(buffer, 0, buffer.Length);
                          zipStream.Write(buffer, 0, sizeRead);
                          size += sizeRead;
                      }
                  }
                  finally
                  {
                      zipStream.Finish();
                      zipStream.Close();
                      streamToZip.Close();
                  }
              }
      
              /// <summary> 
              /// 壓縮單個文件 
              /// </summary> 
              /// <param name="fileToZip">要進行壓縮的文件名,全路徑</param> 
              /// <param name="zipedFile">壓縮后生成的壓縮文件名,全路徑</param> 
              public static void ZipFile(string fileToZip, string zipedFile)
              {
                  // 如果文件沒有找到,則報錯 
                  if (!File.Exists(fileToZip))
                  {
                      throw new FileNotFoundException("指定要壓縮的文件: " + fileToZip + " 不存在!");
                  }
                  using (FileStream fileStream = File.OpenRead(fileToZip))
                  {
                      byte[] buffer = new byte[fileStream.Length];
                      fileStream.Read(buffer, 0, buffer.Length);
                      fileStream.Close();
                      using (FileStream zipFile = File.Create(zipedFile))
                      {
                          using (ZipOutputStream zipOutputStream = new ZipOutputStream(zipFile))
                          {
                              // string fileName = fileToZip.Substring(fileToZip.LastIndexOf("\\") + 1);
                              string fileName = Path.GetFileName(fileToZip);
                              var zipEntry = new ZipEntry(fileName)
                              {
                                  DateTime = DateTime.Now,
                                  IsUnicodeText = true
                              };
                              zipOutputStream.PutNextEntry(zipEntry);
                              zipOutputStream.SetLevel(5);
                              zipOutputStream.Write(buffer, 0, buffer.Length);
                              zipOutputStream.Finish();
                              zipOutputStream.Close();
                          }
                      }
                  }
              }
      
              /// <summary>
              /// 壓縮多個目錄或文件
              /// </summary>
              /// <param name="folderOrFileList">待壓縮的文件夾或者文件,全路徑格式,是一個集合</param>
              /// <param name="zipedFile">壓縮后的文件名,全路徑格式</param>
              /// <param name="password">壓宿密碼</param>
              /// <returns></returns>
              public static bool ZipManyFilesOrDictorys(IEnumerable<string> folderOrFileList, string zipedFile, string password)
              {
                  bool res = true;
                  using (var s = new ZipOutputStream(File.Create(zipedFile)))
                  {
                      s.SetLevel(6);
                      if (!string.IsNullOrEmpty(password))
                      {
                          s.Password = password;
                      }
                      foreach (string fileOrDir in folderOrFileList)
                      {
                          //是文件夾
                          if (Directory.Exists(fileOrDir))
                          {
                              res = ZipFileDictory(fileOrDir, s, "");
                          }
                          else
                          {
                              //文件
                              res = ZipFileWithStream(fileOrDir, s);
                          }
                      }
                      s.Finish();
                      s.Close();
                      return res;
                  }
              }
      
              /// <summary>
              /// 帶壓縮流壓縮單個文件
              /// </summary>
              /// <param name="fileToZip">要進行壓縮的文件名</param>
              /// <param name="zipStream"></param>
              /// <returns></returns>
              private static bool ZipFileWithStream(string fileToZip, ZipOutputStream zipStream)
              {
                  //如果文件沒有找到,則報錯
                  if (!File.Exists(fileToZip))
                  {
                      throw new FileNotFoundException("指定要壓縮的文件: " + fileToZip + " 不存在!");
                  }
                  //FileStream fs = null;
                  FileStream zipFile = null;
                  ZipEntry zipEntry = null;
                  bool res = true;
                  try
                  {
                      zipFile = File.OpenRead(fileToZip);
                      byte[] buffer = new byte[zipFile.Length];
                      zipFile.Read(buffer, 0, buffer.Length);
                      zipFile.Close();
                      zipEntry = new ZipEntry(Path.GetFileName(fileToZip));
                      zipStream.PutNextEntry(zipEntry);
                      zipStream.Write(buffer, 0, buffer.Length);
                  }
                  catch
                  {
                      res = false;
                  }
                  finally
                  {
                      if (zipEntry != null)
                      {
                      }
      
                      if (zipFile != null)
                      {
                          zipFile.Close();
                      }
                      GC.Collect();
                      GC.Collect(1);
                  }
                  return res;
      
              }
      
              /// <summary>
              /// 遞歸壓縮文件夾方法
              /// </summary>
              /// <param name="folderToZip"></param>
              /// <param name="s"></param>
              /// <param name="parentFolderName"></param>
              private static bool ZipFileDictory(string folderToZip, ZipOutputStream s, string parentFolderName)
              {
                  bool res = true;
                  ZipEntry entry = null;
                  FileStream fs = null;
                  Crc32 crc = new Crc32();
                  try
                  {
                      //創(chuàng)建當(dāng)前文件夾
                      entry = new ZipEntry(Path.Combine(parentFolderName, Path.GetFileName(folderToZip) + "/")); //加上 “/” 才會當(dāng)成是文件夾創(chuàng)建
                      s.PutNextEntry(entry);
                      s.Flush();
                      //先壓縮文件,再遞歸壓縮文件夾
                      var filenames = Directory.GetFiles(folderToZip);
                      foreach (string file in filenames)
                      {
                          //打開壓縮文件
                          fs = File.OpenRead(file);
                          byte[] buffer = new byte[fs.Length];
                          fs.Read(buffer, 0, buffer.Length);
                          entry = new ZipEntry(Path.Combine(parentFolderName, Path.GetFileName(folderToZip) + "/" + Path.GetFileName(file)));
                          entry.DateTime = DateTime.Now;
                          entry.Size = fs.Length;
                          fs.Close();
                          crc.Reset();
                          crc.Update(buffer);
                          entry.Crc = crc.Value;
                          s.PutNextEntry(entry);
                          s.Write(buffer, 0, buffer.Length);
                      }
                  }
                  catch
                  {
                      res = false;
                  }
                  finally
                  {
                      if (fs != null)
                      {
                          fs.Close();
                      }
                      if (entry != null)
                      {
                      }
                      GC.Collect();
                      GC.Collect(1);
                  }
                  var folders = Directory.GetDirectories(folderToZip);
                  foreach (string folder in folders)
                  {
                      if (!ZipFileDictory(folder, s, Path.Combine(parentFolderName, Path.GetFileName(folderToZip))))
                      {
                          return false;
                      }
                  }
                  return res;
              }
          }
      }
      

        

       

             歡迎關(guān)注RDIFramework.net框架官方公眾微信微信號:guosisoft),及時了解最新動態(tài)。

             掃描二維碼立即關(guān)注

      posted @ 2017-03-05 10:51  .NET快速開發(fā)框架  閱讀(565)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲成人精品一区二区中| 亚洲va韩国va欧美va| 蜜臀午夜一区二区在线播放| 激情 自拍 另类 亚洲| 国产成人啪精品午夜网站| 久久精品夜夜夜夜夜久久| 国产在线欧美日韩精品一区 | 夜夜影院未满十八勿进| 欧美日本精品一本二本三区| 中文字幕人妻丝袜美腿乱| 精品无码一区二区三区在线| 日本道播放一区二区三区| 亚洲欧洲日产国无高清码图片| 亚洲欧美中文日韩V在线观看 | 成人亚洲精品一区二区三区| 亚洲尤码不卡av麻豆| 久久精品第九区免费观看| 国产精品国产三级国产专| 久久高清超碰AV热热久久| 国产在线观看91精品亚瑟| 欧洲人妻丰满av无码久久不卡| 国产精品一区二区久久岳| 亚洲欧美自偷自拍视频图片| 国产女人高潮视频在线观看| 久久人搡人人玩人妻精品| 亚洲第一无码AV无码专区| 日韩一区二区三区一级片| 亚洲人成网站77777在线观看 | 国产亚洲精品久久久久婷婷瑜伽| 久久精品国产国产精品四凭| 国产成人亚洲日韩欧美| 丁香婷婷色综合激情五月| 久久久久免费看成人影片| 亚洲中文无码手机永久| 亚洲精品国产精品不乱码| 日韩人妻一区中文字幕| 亚洲人妻精品一区二区| 成人污视频| 成人无码h真人在线网站| 亚洲香蕉伊综合在人在线| 欧美精品高清在线观看|