SevenZipArchive

SevenZipArchive constructor (1 of 3)

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

public SevenZipArchive(SevenZipEntrySettings newEntrySettings = null)
Parameter Type Description
newEntrySettings SevenZipEntrySettings Compression 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 3)

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

public SevenZipArchive(Stream sourceStream)
Parameter Type Description
sourceStream Stream The source of the archive.

Exceptions

exception condition
ArgumentException sourceStream is not seekable.
ArgumentNullException sourceStream is null.
NotImplementedException Archive 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 3)

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

public SevenZipArchive(string path)
Parameter Type Description
path String The fully qualified or the relative path to the archive file.

Exceptions

exception condition
ArgumentNullException path is null.
SecurityException The caller does not have the required permission to access
ArgumentException The path is empty, contains only white spaces, or contains invalid characters.
UnauthorizedAccessException Access to file path is denied.
PathTooLongException The 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.
NotSupportedException File 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