C1Zip allows users to zip entire folders without tampering the original folder structure and compress them into a zip archive, and decompress them back.
In this topic, you will learn how to compress and decompress folders using C1.Zip library.
The Zip library provides the AddFolder method in C1ZipEntryCollection to compress an entire folder into a zip file, preserving the folder structure for later expansion. The AddFolder method has many overloads in the class. In the code snippet, we have used the AddFolder(string path, string searchPattern, bool includeSubfolders) method. This overload method uses the parameters such as path, which is the full path of the folder to be added to the zip file, searchPattern, which is a mask that specifies which files to add, and includeSubfolders, which can be set to true to include sub folders, and set to false to only include files at the root level. In the code snippet, the AddFolder method is called on the Entries property of the C1ZipFile object.
The Zip library provides the ExtractFolder method in C1ZipEntryCollection class to extract the contents of the zip file into a specified path. The method has the path parameter, which denotes destination path for the unzipped files. Note that if the zip file contains compressed folders, new folders will be created under the destination path to preserve the hierarchical structure of the zip archive. In the code snippet, the ExtractFolder method is called on the Entries property of the C1ZipFile object.