How to: Archive Selected Files
To archive selected files create a ZipArchive class instance and call its AddFile method for each selected file.
To store a file without its path, call the ZipArchive.AddFile method with the “/“ parameter. The file is placed in the root node of the archive. Call the ZipArchive.Save method. The archive is created and saved to a specified location.
This code snippet demonstrates how to create a new archive and add files with .txt and .docx extensions to the archive root. The ZipArchive.Save method compresses data and saves the archive to a file.
using DevExpress.Compression;
public void ArchiveFiles() {
string[] sourcefiles = this.sourceFiles;
string[] ext = new string[] {".txt", ".docx"};
using (ZipArchive archive = new ZipArchive()) {
foreach (string file in sourcefiles) {
if (ext.Contains(Path.GetExtension(file)))
archive.AddFile(file, "/");
}
archive.Save("Documents\\ArchiveFiles.zip");
}
}