Skip to main content

ZipArchive.AddFile(String, String) Method

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

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v24.1.dll

NuGet Package: DevExpress.Document.Processor

Declaration

public ZipFileItem AddFile(
    string fileName,
    string relativePath
)

Parameters

Name Type Description
fileName String

A string that is the path to the file.

relativePath String

A string that is the path in the archive.

Returns

Type Description
ZipFileItem

A ZipFileItem that is the file item in the archive.

Remarks

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

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddFile(String, String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also