Skip to main content
A newer version of this page is available. .

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.v18.2.dll

Declaration

public ZipFileItem AddFile(
    string fileName
)

Parameters

Name Type Description
fileName String

A string that is the path to the file.

Returns

Type Description
ZipFileItem

A ZipFileItem that is the file item in the archive.

Remarks

This method adds the specified file to the archive. The path in the archive is constructed from the file path so that if the file path is rooted, the archive path is the path to the root; otherwise, the path in archive is composed of the same components as the file path. It means that the file “C:\Temp\AAA\BBB\winnipooh.txt” is added to the archive as a ZipFileItem with the ZipItem.Name that equals “Temp/AAA/BBB/winnipooh.txt” (archive path) and a ZipFileItem.FileName that equals “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.

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