Skip to main content

How to: Archive Selected Files

To archive selected files, do the following:

  1. Create a ZipArchive class instance.
  2. Call its ZipArchive.AddFile method for each selected file.
  3. 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.
  4. 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.

View Example

using DevExpress.Compression;
        public void ArchiveFiles() {
            string[] sourcefiles = this.sourceFiles;
            using (ZipArchive archive = new ZipArchive()) {
                foreach (string file in sourcefiles) {
                    archive.AddFile(file, "/");