Skip to main content

ZipArchive.Read(String) Method

Static method that creates a ZipArchive instance from the specified archive file.

Namespace: DevExpress.Compression

Assembly: DevExpress.Docs.v23.2.dll

NuGet Package: DevExpress.Document.Processor

Declaration

public static ZipArchive Read(
    string fileName
)

Parameters

Name Type Description
fileName String

A string that is the path to the archive file.

Returns

Type Description
ZipArchive

A ZipArchive instance that is the zip archive for modification or extraction.

Remarks

Use the Read method to open the archive for modification or extraction. To save the archive, use the corresponding ZipArchive.Save method override.

Example

When the file archive is opened with the ZipArchive.Read method, you cannot save it to the same file. The ZipArchive.Save method attempts to overwrite the locked file resulting in an exception.

This code snippet illustrates how you can add a file to an archive and save it with the same name as before.

View Example

public void AddFileToArchive() {
    MemoryStream stream = new MemoryStream();
    string[] sourcefiles = this.sourceFiles;
    string pathToZipArchive = "Documents\\Example.zip";

    using (FileStream fs = File.Open(pathToZipArchive, FileMode.Open)) {
        fs.CopyTo(stream);
        fs.Close();
    }
    stream.Seek(0, SeekOrigin.Begin);
    using (ZipArchive archive = ZipArchive.Read(stream, System.Text.Encoding.Default, false)) {
        foreach (string sfile in sourcefiles) {
            archive.AddFile(sfile, "/");
        }
        archive.Save(pathToZipArchive);
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Read(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