ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 278.7k

How to customize function compress by zip to accept extensio

Jun 8 2020 3:59 AM
I work on c# app doing compress to file using ziparchieve 
my dot net version 4.7 
  1. CreateZipFile(string fileName, out List files, extension type xlsx)   
I need to pass extension type as optional parameter and if no extension type passed then select all files on folder
if extension type as xlsx passed then compress files that have extension xlsx only
also I need list of string files as out because may be I used again
  1. public static void CreateZipFile(string fileName, List files)  
  2. {  
  3.     using (ZipArchive zip = ZipFile.Open(fileName, ZipArchiveMode.Update))  
  4.     {  
  5.         foreach (var file in files)  
  6.         {  
  7.             if (!zip.Entries.Any(zipFile => file.Contains(zipFile.FullName)))  
  8.             {  
  9.                 zip.CreateEntryFromFile(file, Path.GetFileName(file), CompressionLevel.Optimal);  
  10.             }  
  11.         }  
  12.     }