Skip to main content
.NET Framework 4.5.2+

ZipArchive.AddFile(String) Method

Creates a zip file item for the specified file and adds it to the archive.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v22.2.dll


public ZipFileItem AddFile(
    string fileName


Name Type Description
fileName String

A string that is the path to the file.


Type Description

A ZipFileItem that is the file item in the archive.


This method adds the specified file to the archive. The path in the archive is constructed the following way:

  • For rooted paths - the path is the path to the root;
  • For other paths - the path is relative to the file path.

For example, the file “C:\Temp\AAA\BBB\winnipooh.txt” is added to the archive as a ZipFileItem with the ZipItem.Name property set to “Temp/AAA/BBB/winnipooh.txt” (archive path) and a ZipFileItem.FileName property set to “C:\Temp\AAA\BBB\winnipooh.txt” (file path).

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, "/");
See Also