How to: Archive Selected Files
To archive selected files, do the following:
- Create a ZipArchive class instance.
- Call its ZipArchive.AddFile method for each selected file.
- To store a file without its path, call the ZipArchive.AddFile method with the “/“ parameter. The file will be placed in the root node of the archive.
- Call the ZipArchive.Save method. The archive will be created and saved to a specified location.
This code snippet demonstrates how to create a new archive and add files to the archive root. The ZipArchive.Save method compresses data and saves the archive to a file.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/compression-library-examples-e4695
using DevExpress.Compression;
public void ArchiveFiles() {
string[] sourcefiles = this.sourceFiles;
using (ZipArchive archive = new ZipArchive()) {
foreach (string file in sourcefiles) {
archive.AddFile(file, "/");
}
archive.Save("Documents\\ArchiveFiles.zip");
}
}