SevenZipArchive

SevenZipArchive constructor (1 of 4)

Initializes a new instance of the SevenZipArchive class with optional settings for its entries.

public SevenZipArchive(SevenZipEntrySettings newEntrySettings = null)
ParameterTypeDescription
newEntrySettingsSevenZipEntrySettingsCompression and encryption settings used for newly added SevenZipArchiveEntry items. If not specified, LZMA compression without encryption would be used.

Examples

The following example shows how to compress a single file with default settings: LZMA compression without encryption.

using (FileStream sevenZipFile = File.Open("archive.7z", FileMode.Create))
{
    using (var archive = new SevenZipArchive())
    {
        archive.CreateEntry("data.bin", "file.dat");
        archive.Save(sevenZipFile);
    }
}

See Also


SevenZipArchive constructor (2 of 4)

Initializes a new instance of the SevenZipArchive class and composes entries list can be extracted from the archive.

public SevenZipArchive(Stream sourceStream, string password = null)
ParameterTypeDescription
sourceStreamStreamThe source of the archive.
passwordStringOptional password for decryption. If file names are encrypted it must be present.

Exceptions

exceptioncondition
ArgumentExceptionsourceStream is not seekable.
ArgumentNullExceptionsourceStream is null.
NotImplementedExceptionArchive contains more than one coder. Now only LZMA compression supported.

Remarks

This constructor does not decompress any entry. See ExtractToDirectory method for decompressing.

Examples

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

See Also


SevenZipArchive constructor (3 of 4)

Initializes a new instance of the SevenZipArchive class and composes entries list can be extracted from the archive.

public SevenZipArchive(string path, string password = null)
ParameterTypeDescription
pathStringThe fully qualified or the relative path to the archive file.
passwordStringOptional password for decryption. If file names are encrypted it must be present.

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.

Remarks

This constructor does not decompress any entry. See ExtractToDirectory method for decompressing.

Examples

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

See Also


SevenZipArchive constructor (4 of 4)

Initializes a new instance of the SevenZipArchive class from multi-volume 7z archive and composes entries list can be extracted from the archive.

public SevenZipArchive(string[] parts, string password = null)
ParameterTypeDescription
partsString[]Paths to each segment of multi-volume 7z archive respecting order
passwordStringOptional password for decryption. If file names are encrypted it must be present.

Exceptions

exceptioncondition
ArgumentNullExceptionparts is null.
ArgumentExceptionparts has no entries.
SecurityExceptionThe caller does not have the required permission to access.
ArgumentExceptionThe path to a file is empty, contains only white spaces, or contains invalid characters.
UnauthorizedAccessExceptionAccess to a file is denied.
PathTooLongExceptionThe specified path to a part, 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.

Examples

using (SevenZipArchive archive = new SevenZipArchive(new string[] { "multi.7z.001", "multi.7z.002", "multi.7z.003" } ))
{
    archive.ExtractToDirectory("C:\\extracted");
}

See Also