C# ZipFileExtensions ExtractToFile(ZipArchiveEntry, String)

Description

ZipFileExtensions ExtractToFile(ZipArchiveEntry, String) Extracts an entry in the zip archive to a file.

Syntax

ZipFileExtensions.ExtractToFile(ZipArchiveEntry, String) has the following syntax.


public static void ExtractToFile(
  this ZipArchiveEntry source,
  string destinationFileName
)

Parameters

ZipFileExtensions.ExtractToFile(ZipArchiveEntry, String) 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.

Returns

ZipFileExtensions.ExtractToFile(ZipArchiveEntry, String) method returns

Example


using System;//from   w  w  w .ja  v a2 s.c  o  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));
                }
            }
        } 
    }
}




















Home »
  C# Tutorial »
    System.IO.Compression »




DeflateStream
GZipStream
ZipArchive
ZipArchiveEntry
ZipFile
ZipFileExtensions