C# ZipFileExtensions ExtractToFile(ZipArchiveEntry, String, Boolean)
Description
ZipFileExtensions ExtractToFile(ZipArchiveEntry, String,
Boolean)
Extracts an entry in the zip archive to a file, and optionally
overwrites an existing file that has the same name.
Syntax
ZipFileExtensions.ExtractToFile(ZipArchiveEntry, String, Boolean)
has the following syntax.
public static void ExtractToFile(
this ZipArchiveEntry source,
string destinationFileName,//from www . ja va 2 s . c o m
bool overwrite
)
Parameters
ZipFileExtensions.ExtractToFile(ZipArchiveEntry, String, Boolean)
has the following parameters.
source
- The zip archive entry to extract a file from.destinationFileName
- The path of the file to create from the contents of the entry. You can specify either a relative or an absolute path. A relative path is interpreted as relative to the current working directory.overwrite
- true to overwrite an existing file that has the same name as the destination file; otherwise, false.
Returns
ZipFileExtensions.ExtractToFile(ZipArchiveEntry, String, Boolean)
method returns
Example
using System;//from ww w. ja va 2 s.co m
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), true);
}
}
}
}
}