.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

ZipArchive.AddFiles(IEnumerable<String>) Method

Adds files to archive.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v21.1.dll

Declaration

public void AddFiles(
    IEnumerable<string> fileNames
)

Parameters

Name Type Description
fileNames IEnumerable<String>

A list of file names which implements the IEnumerable<T><String,> interface.

Remarks

The AddFiles method enables you to batch add files to the archive. The archive path to which the files will be added is constructed from the file path by discarding the root path component, i.e., the file path “C:\Temp\test.txt” will be the “Temp/test.txt”.

This example recursively enumerates all files that have a .txt extension, reads each line of the file, and if a line contains the string “DevExpress”, the file is added to archive.

using DevExpress.Compression;
        public void ArchiveFilesBatch() {
            string path = this.startupPath;
            using (ZipArchive archive = new ZipArchive()) {
                var files = from file in System.IO.Directory.EnumerateFiles(path, "*.xml",
                                System.IO.SearchOption.AllDirectories)
                            from line in System.IO.File.ReadLines(file)
                            where line.Contains("DevExpress")
                            select file;
                archive.AddFiles(files);
                archive.Save("Documents\\ArchiveFilesBatch.zip");
            }
        }
See Also