amritha O

amritha O

  • NA
  • 16
  • 24.7k

Zip multiple files then save to a shared location

Jun 24 2020 1:37 AM
Hi

Im trying to zip some excel and xml files using c# using ionic.zip dll
  1. ZipFile zip = new ZipFile();  
  2. zip.AlternateEncodingUsage = ZipOption.AsNecessary;  
  3. zip.AddDirectoryByName("Files");  
  4. foreach (string filepath in folderPaths)  
  5. {  
  6. zip.AddFile(filepath, "Files");  
  7. }  
  8. string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));  
  9. zip.Save(Path.Combine(folderPath, zipName));  
  10. foreach (string filepath in folderPaths)  
  11. {  
  12. if ((System.IO.File.Exists(Path.Combine(filepath))))  
  13. {  
  14. System.IO.File.Delete(Path.Combine(filepath));  
  15. }  
  16. }  
above code works well but issue is a directory name files inside zip folder i want to remove this

when i remove zip.AddDirectoryByName("Files"); this code a folder with folderPath creatind instead of files .How to remove this .How files directly coming under zip folder

Answers (1)