SevenZipArchive.ExtractToDirectory

SevenZipArchive.ExtractToDirectory method

Extracts all the files in the archive to the directory provided.

public void ExtractToDirectory(string destinationDirectory, string password = null)
ParameterTypeDescription
destinationDirectoryStringThe path to the directory to place the extracted files in.
passwordStringOptional password for content decryption.

Exceptions

exceptioncondition
ArgumentNullExceptiondestinationDirectory is null.
PathTooLongExceptionThe specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must be less than 248 characters and file names must be less than 260 characters.
SecurityExceptionThe caller does not have the required permission to access the existing directory.
NotSupportedExceptionIf the directory does not exist, the path contains a colon character (:) that is not part of a drive label (“C:").
ArgumentExceptiondestinationDirectory is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the System.IO.Path.GetInvalidPathChars method. -or- path is prefixed with, or contains, only a colon character (:).
IOExceptionThe directory specified by path is a file. -or- The network name is not known.
InvalidDataExceptionThe archive is corrupted.
ObjectDisposedExceptionArchive has been disposed and cannot be used.
OperationCanceledExceptionIn .NET Framework 4.0 and above: Thrown when the extraction is canceled via the provided cancellation token.

Remarks

If the directory does not exist, it will be created.

password is used for content decryption only. If file names are encrypted provide password in SevenZipArchive, SevenZipArchive, SevenZipArchive or SevenZipArchive constructor.

Examples

using (var archive = new SevenZipArchive("archive.7z")) 
{ 
   archive.ExtractToDirectory("C:\extracted");
}

See Also