ArchiveEntry.Extract

Extract(string, string)

Extracts the entry to the filesystem by the path provided.

public FileInfo Extract(string path, string password = null)
ParameterTypeDescription
pathStringThe path to destination file. If the file already exists, it will be overwritten.
passwordStringOptional password for decryption.

Return Value

The file info of composed file.

Exceptions

exceptioncondition
ArgumentNullExceptionpath is null.
SecurityExceptionThe caller does not have the required permission to access.
ArgumentExceptionThe path is empty, contains only white spaces, or contains invalid characters.
UnauthorizedAccessExceptionAccess to file path is denied.
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.
NotSupportedExceptionFile at path contains a colon (:) in the middle of the string.
FileNotFoundExceptionThe file is not found.
DirectoryNotFoundExceptionThe specified path is invalid, such as being on an unmapped drive.
IOExceptionThe file is already open.
InvalidDataExceptionData is corrupted. -or- CRC or MAC verification failed for the entry.

Examples

Extract two entries of zip archive, each with own password

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract("first.bin", "first_pass");
        archive.Entries[1].Extract("second.bin", "second_pass");
    }
}

See Also


Extract(Stream, string)

Extracts the entry to the stream provided.

public void Extract(Stream destination, string password = null)
ParameterTypeDescription
destinationStreamDestination stream. Must be writable.
passwordStringOptional password for decryption.

Exceptions

exceptioncondition
InvalidDataExceptionData is corrupted. -or- CRC or MAC verification failed for the entry.
IOExceptionSource is corrupted or not readable.
ArgumentExceptiondestination does not support writing.

Examples

Extract an entry of zip archive with password.

using (FileStream zipFile = File.Open("archive.zip", FileMode.Open))
{
    using (Archive archive = new Archive(zipFile))
    {
        archive.Entries[0].Extract(httpResponseStream, "p@s$");
    }
}

See Also