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

0 votes
asked Jan 3, 2011 by Rebex KB (8,210 points)
edited Mar 28, 2011

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

Applies to: Rebex ZIP

1 Answer

0 votes
answered Jan 3, 2011 by Rebex KB (8,210 points)
edited Jan 3, 2011
 
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 
  ); 
}
...