ZipFile.OpenRead Method

.NET Framework 4.5

Opens a zip archive for reading at the specified path.

Namespace:  System.IO.Compression
Assembly:  System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)

public static ZipArchive OpenRead(
	string archiveFileName


Type: System.String

The path to the archive to open, specified as a relative or absolute path. A relative path is interpreted as relative to the current working directory.

Return Value

Type: System.IO.Compression.ZipArchive
The opened zip archive.


archiveFileName is Empty, contains only white space, or contains at least one invalid character.


archiveFileName is null.


In archiveFileName, the specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must not exceed 248 characters, and file names must not exceed 260 characters.


archiveFileName is invalid or does not exist (for example, it is on an unmapped drive).


archiveFileName could not be opened.


archiveFileName specifies a directory.


The caller does not have the required permission to access the file specified in archiveFileName.


The file specified in archiveFileName is not found.


archiveFileName contains an invalid format.


archiveFileName could not be interpreted as a zip archive.

This method is equivalent to calling the Open method and setting the mode parameter to Read. The archive is opened with FileMode.Open as the file mode value. If the archive does not exist, a FileNotFoundException exception is thrown.

The following example shows how to open a zip archive for reading.

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            string zipPath = @"c:\example\";
            string extractPath = @"c:\example\extract";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
                foreach (ZipArchiveEntry entry in archive.Entries)
                    if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                        entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));

.NET Framework

Supported in: 4.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft