Skip to content

Comprizip #12502

@DaryRiverou

Description

@DaryRiverou

$ Skip to main contentSkip to in-page navigation
Microsoft Build 2026 June 2-3, 2026

Learn
Sign in
Learn
ZipFileExtensions.ExtractToDirectory Method
In this article
Definition
Overloads
ExtractToDirectory(ZipArchive, String) ExtractToDirectory(ZipArchive, String, Boolean)
Definition Namespace:
System.IO.Compression
Assemblies:
netstandard.dll, System.IO.Compression.ZipFile.dll
Overloads
Name Description
ExtractToDirectory(ZipArchive, String) Extracts all the files in the zip archive to a directory on the file system.

ExtractToDirectory(ZipArchive, String, Boolean)
Extracts all of the files in the archive to a directory on the file system.

ExtractToDirectory(ZipArchive, String)
Source:
ZipFileExtensions.ZipArchive.Extract.cs
Extracts all the files in the zip archive to a directory on the file system.
csharp
public static void ExtractToDirectory(this System.IO.Compression.ZipArchive source, string destinationDirectoryName);
Parameters
source
ZipArchive
The zip archive to extract files from.

destinationDirectoryName
String
The path to the directory to place the extracted files in. You can specify either a relative or an absolute path. A relative path is interpreted as relative to the current working directory.

Exceptions
ArgumentException
destinationDirectoryName is Empty, contains only white space, or contains at least one invalid character.

ArgumentNullException
destinationDirectoryName is null.

PathTooLongException
The specified path exceeds the system-defined maximum length.

DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).

IOException
The name of an entry in the archive is Empty, contains only white space, or contains at least one invalid character.

-or-

Extracting an entry from the archive would create a file that is outside the directory specified by destinationDirectoryName. (For example, this might happen if the entry name contains parent directory accessors.)

-or-

Two or more entries in the archive have the same name.

UnauthorizedAccessException
The caller does not have the required permission to write to the destination directory.

NotSupportedException
destinationDirectoryName contains an invalid format.

InvalidDataException
An archive entry cannot be found or is corrupt.

-or-

An archive entry was compressed by using a compression method that is not supported.

Examples
The following example shows how to create a new entry in a zip archive from an existing file, and extract the archive to a new directory.

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

namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string zipPath = @"c:\users\exampleuser\start.zip";
string extractPath = @"c:\users\exampleuser\extract";
string newFile = @"c:\users\exampleuser\NewFile.txt";

        using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Update))
        {
            archive.CreateEntryFromFile(newFile, "NewEntry.txt");
            archive.ExtractToDirectory(extractPath);
        }
    }
}

}
Remarks
This method creates the directory specified by destinationDirectoryName. The method also creates subdirectories that reflect the hierarchy in the zip archive. If an error occurs during extraction, the archive remains partially extracted. Each extracted file has the same relative path to the directory specified by destinationDirectoryName as its source entry has to the root of the archive.

Applies to
net-10.0 net-10.0
ExtractToDirectory(ZipArchive, String, Boolean)
Source:
ZipFileExtensions.ZipArchive.Extract.cs
Extracts all of the files in the archive to a directory on the file system.

csharp
public static void ExtractToDirectory(this System.IO.Compression.ZipArchive source, string destinationDirectoryName, bool overwriteFiles);
Parameters
source
ZipArchive
The ZipArchive to extract.

destinationDirectoryName
String
The path to the destination directory on the file system. The path can be relative or absolute. A relative path is interpreted as relative to the current working directory.

overwriteFiles
Boolean
true to overwrite existing files; false otherwise.

Exceptions
ArgumentException
destinationDirectoryName is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.

ArgumentNullException
destinationDirectoryName is null.

PathTooLongException
The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException
The specified path is invalid (for example, it is on an unmapped drive).

IOException
The name of a ZipArchiveEntry is zero-length, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.

-or-

Extracting a ZipArchiveEntry would have resulted in a destination file that is outside destinationDirectoryName (for example, if the entry name contains parent directory accessors).

-or-

A ZipArchiveEntry has the same name as an already extracted entry from the same archive.

UnauthorizedAccessException
The caller does not have the required permission.

NotSupportedException
destinationDirectoryName is in an invalid format.

InvalidDataException
A ZipArchiveEntry was not found or was corrupt.

-or-

A ZipArchiveEntry has been compressed using a compression method that is not supported.

Remarks
The specified directory may already exist. This method creates the specified directory and all subdirectories if necessary.

If there is an error while extracting the archive, the archive will remain partially extracted.

Each entry is extracted such that the extracted file has the same relative path to destinationDirectoryName as the entry has to the root of the archive.

If a file to be archived has an invalid last modified time, the first date and time representable in the Zip timestamp format (midnight on January 1, 1980) is used.

Applies to
net-10.0 net-10.0
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.

.NET feedback

.NET is an open source project. Select a link to provide feedback:

Open a documentation issue
Provide product feedback
Feedback
Was this page helpful?

AI Disclaimer
Previous Versions
Blog
Contribute
Privacy
Consumer Health Privacy
Terms of Use
Trademarks
© Microsoft 2026
No command Skip found, did you mean:
Command gzip in package gzip
Command hzip in package hunspell
Command ip in package iproute2
Command lzip in package lzip
Command mzip in package mtools
Command pip in package python-pip
Command rip in package rip2
Command zip in package zip
Microsoft: command not found
No command June found, did you mean:
Command cuse in package cuse from the x11-repo repository
Command prune in package graphviz
Command line in package mesa-demos from the x11-repo repository
Command ifne in package moreutils
Command ne in package ne
Command runc in package runc from the root-repo repository
Command sun in package sun
No command Learn found, did you mean:
Command rearj in package arj
Command bear in package bear
Command gears in package mesa-demos from the x11-repo repository
Command yarn in package yarn
No command Sign found, did you mean:
Command dig in package dnsutils
Command ein in package gitoxide
Command gn in package gn
Command pigz in package pigz
Command rig in package rig
Command tig in package tig
No command Learn found, did you mean:
Command rearj in package arj
Command bear in package bear
Command gears in package mesa-demos from the x11-repo repository
Command yarn in package yarn
ZipFileExtensions.ExtractToDirectory: command not found
No command In found, did you mean:
Command ln in package coreutils
Command gn in package gn
Command sn in package mono
Command sn in package tin-summer
Definition: command not found
Overloads: command not found
bash: syntax error near unexpected token ZipArchive,' bash: syntax error near unexpected token ZipArchive,'
Definition: command not found
Namespace:: command not found
System.IO.Compression: command not found
Assemblies:: command not found
netstandard.dll,: command not found
Overloads: command not found
No command Name found, did you mean:
Command lame in package lame
bash: syntax error near unexpected token ZipArchive,' No command Extracts found, did you mean: Command extractbb in package texlive-bin bash: syntax error near unexpected token ZipArchive,'
No command Extracts found, did you mean:
Command extractbb in package texlive-bin
bash: syntax error near unexpected token `ZipArchive,'
No command Source: found, did you mean:
Command bounce in package mesa-demos from the x11-repo repository
Command pounce in package pounce
ZipFileExtensions.ZipArchive.Extract.cs: command not found
No command Extracts found, did you mean:
Command extractbb in package texlive-bin
Mono C# Shell, type "help;" for help

Enter statements below.
csharp>
csharp> ln
(1,2): error CS0103: The name ln' does not exist in the current context csharp> lx (1,2): error CS0103: The name lx' does not exist in the current context
csharp> ln
(1,2): error CS0103: The name ln' does not exist in the current context csharp> lx (1,2): error CS0103: The name lx' does not exist in the current context
csharp>

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IO.Compressioncode-of-conductIndicates issues that are spam, trolling, or anything that violates our code of conductuntriagedNew issue has not been triaged by the area owner

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions