SevenZipArchive.SevenZipArchive
SevenZipArchive(SevenZipEntrySettings)
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
- class SevenZipEntrySettings
- class SevenZipArchive
- namespace Aspose.Zip.SevenZip
- assembly Aspose.Zip
SevenZipArchive(Stream, string)
Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.
public SevenZipArchive(Stream sourceStream, string password = null)
| Parameter | Type | Description |
|---|---|---|
| sourceStream | Stream | The source of the archive. |
| password | String | Optional password for decryption. If file names are encrypted, it must be present. |
Exceptions
| exception | condition |
|---|---|
| ArgumentException | sourceStream is not seekable. |
| ArgumentNullException | sourceStream is null. |
| NotImplementedException | The 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
- class SevenZipArchive
- namespace Aspose.Zip.SevenZip
- assembly Aspose.Zip
SevenZipArchive(string, string)
Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.
public SevenZipArchive(string path, string password = null)
| Parameter | Type | Description |
|---|---|---|
| path | String | The fully qualified or the relative path to the archive file. |
| password | String | Optional password for decryption. If file names are encrypted, it must be present. |
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. |
| FileNotFoundException | The file is not found. |
| DirectoryNotFoundException | The specified path is invalid, such as being on an unmapped drive. |
| IOException | The file is already open. |
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
- class SevenZipArchive
- namespace Aspose.Zip.SevenZip
- assembly Aspose.Zip
SevenZipArchive(Stream, SevenZipLoadOptions)
Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.
public SevenZipArchive(Stream sourceStream, SevenZipLoadOptions options)
| Parameter | Type | Description |
|---|---|---|
| sourceStream | Stream | The source of the archive. |
| options | SevenZipLoadOptions | Options to load existing archive with. |
Exceptions
| exception | condition |
|---|---|
| ArgumentException | sourceStream is not seekable. |
| ArgumentNullException | sourceStream is null. |
| NotImplementedException | The 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
Extract an encrypted archive. Allow up to 60 seconds to proceed, cancel after that period.
using(CancellationTokenSource cts = new CancellationTokenSource())
{
SevenZipLoadOptions options = new SevenZipLoadOptions(){ DecryptionPassword = "Top$ecr3t", CancellationToken = cts.Token }
cts.CancelAfter(TimeSpan.FromSeconds(60));
using (SevenZipArchive archive = new SevenZipArchive(File.OpenRead("archive.7z"), options))
{
archive.ExtractToDirectory("C:\\extracted");
}
}
See Also
- class SevenZipLoadOptions
- class SevenZipArchive
- namespace Aspose.Zip.SevenZip
- assembly Aspose.Zip
SevenZipArchive(string, SevenZipLoadOptions)
Initializes a new instance of the SevenZipArchive class and composes an entry list can be extracted from the archive.
public SevenZipArchive(string path, SevenZipLoadOptions options)
| Parameter | Type | Description |
|---|---|---|
| path | String | The fully qualified or the relative path to the archive file. |
| options | SevenZipLoadOptions | Options to load existing archive with. |
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. |
| FileNotFoundException | The file is not found. |
| DirectoryNotFoundException | The specified path is invalid, such as being on an unmapped drive. |
| IOException | The file is already open. |
Remarks
This constructor does not decompress any entry. See ExtractToDirectory method for decompressing.
Examples
Extract an encrypted archive. Allow up to 60 seconds to proceed, cancel after that period.
using(CancellationTokenSource cts = new CancellationTokenSource())
{
SevenZipLoadOptions options = new SevenZipLoadOptions(){ DecryptionPassword = "Top$ecr3t", CancellationToken = cts.Token }
cts.CancelAfter(TimeSpan.FromSeconds(60));
using (SevenZipArchive archive = new SevenZipArchive(File.OpenRead("archive.7z"), options))
{
archive.ExtractToDirectory("C:\\extracted");
}
}
See Also
- class SevenZipLoadOptions
- class SevenZipArchive
- namespace Aspose.Zip.SevenZip
- assembly Aspose.Zip
SevenZipArchive(string[], string)
Initializes a new instance of the SevenZipArchive class from multi-volume 7z archive and composes an entry list can be extracted from the archive.
public SevenZipArchive(string[] parts, string password = null)
| Parameter | Type | Description |
|---|---|---|
| parts | String[] | Paths to each segment of multi-volume 7z archive respecting order |
| password | String | Optional password for decryption. If file names are encrypted, it must be present. |
Exceptions
| exception | condition |
|---|---|
| ArgumentNullException | parts is null. |
| ArgumentException | parts has no entries. |
| SecurityException | The caller does not have the required permission to access. |
| ArgumentException | The path to a file is empty, contains only white spaces, or contains invalid characters. |
| UnauthorizedAccessException | Access to a file is denied. |
| PathTooLongException | The 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. |
| NotSupportedException | File at a 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
- class SevenZipArchive
- namespace Aspose.Zip.SevenZip
- assembly Aspose.Zip