Guest User

Untitled

a guest
May 26th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. using System.IO.Compression;
  2.  
  3. public bool QuickZip(string[] filesToZip, string destinationZipFullPath)
  4. {
  5. try
  6. {
  7. // Delete existing zip file if exists
  8. if (File.Exists(destinationZipFullPath))
  9. File.Delete(destinationZipFullPath);
  10.  
  11. using (ZipArchive zip = ZipFile.Open(destinationZipFullPath, ZipArchiveMode.Create))
  12. {
  13. foreach (var file in filesToZip)
  14. {
  15. zip.CreateEntryFromFile(file, Path.GetFileName(file), CompressionLevel.Optimal);
  16. }
  17. }
  18.  
  19. return File.Exists(destinationZipFullPath);
  20. }
  21. catch (Exception e)
  22. {
  23. Console.WriteLine($"Exception: {e.Message}");
  24. return false;
  25. }
  26. }
Add Comment
Please, Sign In to add comment