Sample: Simple ZIP
Demonstrates how to create a ZIP archive and add files to it.
Usage
=====================================================================
SimpleZip.exe
=====================================================================
Adds files to a ZIP archive
Syntax: SimpleZip.exe zip-file-path [path-or-mask]
Example: SimpleZip.exe c:\archive.zip c:\data\*.txt
More info
The following code snippet is the core of the sample:
C#
// open or create a ZIP archive and add files to it
using (ZipArchive archive = new ZipArchive(@"c:\archive.zip"))
{
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
);
}
VB.NET
' open or create a ZIP archive and add files to it
Using archive As New ZipArchive("c:\archive.zip")
Dim result As ArchiveOperationResult = archive.Add( _
"*", _
"/", _
ArchiveTraversalMode.Recursive, _
ArchiveActionOnExistingFile.OverwriteAll)
Console.WriteLine( _
"Added {0} file(s), {1} byte(s) to {2}.", _
result.FilesAffected, _
result.FilesUncompressedLength, _
archive.FilePath)
End Using
For more info see "Adding files to a ZIP archive - Compressing" tutorial.
See also: