0 votes
by (8.4k points)
edited

How to create a zip file and add files to it in C#?

Applies to: Rebex ZIP

1 Answer

0 votes
by (8.4k points)
edited
 
Best answer

Following code shows how to create a Zip file and add files to it using Rebex ZIP component.

// open or create a ZIP archive and add files to it 
using (ZipArchive archive = new ZipArchive(config.ZipArchivePath)) 
{
  ArchiveOperationResult result = archive.Add( 
    "*", 
    @"\", 
    ArchiveTraversalMode.Recursive, 
    ArchiveActionOnExistingFile.OverwriteAll 
  ); 
  Console.WriteLine( 
    "Added {0} file(s), {1} byte(s) to {2}.", 
    result.FilesAffected, 
    result.FilesUncompressedLength, 
    archive.FilePath 
  ); 
}
...