Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

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.

View Example

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");
    }
}