C# ZipFile OpenRead
Description
ZipFile OpenRead
Opens a zip archive for reading at the
specified path.
Syntax
ZipFile.OpenRead
has the following syntax.
public static ZipArchive OpenRead(
string archiveFileName
)
Parameters
ZipFile.OpenRead
has the following parameters.
archiveFileName
- 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.
Returns
ZipFile.OpenRead
method returns The opened zip archive.
Example
The following example shows how to open a zip archive for reading.
/*w w w .j a v a 2 s . c o m*/
using System;
using System.IO;
using System.IO.Compression;
class Program
{
static void Main(string[] args)
{
string zipPath = @"c:\example\start.zip";
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));
}
}
}
}
}