CabArchive.CreateEntry
Contents
[
Hide
]CreateEntry(string, string, CabEntrySettings)
Create a single entry within the archive.
public CabEntry CreateEntry(string name, string path, CabEntrySettings newEntrySettings = null)
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the entry. |
| path | String | The fully qualified name of the new file, or the relative file name to be compressed. |
| newEntrySettings | CabEntrySettings | Compression and encryption settings used for added CabEntry item. |
Return Value
Cab entry instance.
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. |
| ObjectDisposedException | Archive has been disposed and cannot be used. |
| InvalidOperationException | The archive is prepared for extraction and cannot add entries. |
Remarks
The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.
Examples
using (var archive = new CabArchive())
{
archive.CreateEntry("entry.bin", "data.bin");
archive.Save("archive.cab");
}
See Also
- class CabEntry
- class CabEntrySettings
- class CabArchive
- namespace Aspose.Zip.Cab
- assembly Aspose.Zip
CreateEntry(string, Stream, CabEntrySettings)
Create a single entry within the archive.
public CabEntry CreateEntry(string name, Stream source, CabEntrySettings newEntrySettings = null)
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the entry. |
| source | Stream | The input stream for the entry. |
| newEntrySettings | CabEntrySettings | Compression and encryption settings used for added CabEntry item. |
Return Value
Cab entry instance.
Exceptions
| exception | condition |
|---|---|
| ObjectDisposedException | Archive has been disposed and cannot be used. |
| InvalidOperationException | The archive is prepared for extraction and cannot add entries. |
Examples
using (var archive = new CabArchive())
{
using (var dataStream = new MemoryStream(File.ReadAllBytes("data.bin")))
{
archive.CreateEntry("stream-entry.bin", dataStream);
archive.Save("archive.cab");
}
}
using (var archive = new CabArchive())
{
var settings = new CabEntrySettings(new CabStoreCompressionSettings());
archive.CreateEntry("stream-entry.bin", dataStream, settings);
archive.Save("archive.cab");
}
See Also
- class CabEntry
- class CabEntrySettings
- class CabArchive
- namespace Aspose.Zip.Cab
- assembly Aspose.Zip
CreateEntry(string, FileInfo, CabEntrySettings)
Create a single entry within the archive.
public CabEntry CreateEntry(string name, FileInfo fileInfo,
CabEntrySettings newEntrySettings = null)
| Parameter | Type | Description |
|---|---|---|
| name | String | The name of the entry. |
| fileInfo | FileInfo | The metadata of file to be compressed. |
| newEntrySettings | CabEntrySettings | Compression and encryption settings used for added CabEntry item. |
Return Value
Cab entry instance.
Exceptions
| exception | condition |
|---|---|
| UnauthorizedAccessException | fileInfo is read-only or is a directory. |
| DirectoryNotFoundException | The specified path is invalid, such as being on an unmapped drive. |
| IOException | The file is already open. |
| FileNotFoundException | fileInfo represents a file that cannot be found. |
| SecurityException | The caller does not have the required permission to access fileInfo. |
| ObjectDisposedException | Archive has been disposed and cannot be used. |
| InvalidOperationException | The archive is prepared for extraction and cannot add entries. |
Remarks
The entry name is solely set within name parameter. The file name provided in fileInfo parameter does not affect the entry name.
Examples
using (var archive = new CabArchive(new CabEntrySettings(new CabMsZipCompressionSettings())))
{
var sourceFile = new FileInfo("logs\\log.txt");
archive.CreateEntry("log.txt", sourceFile);
archive.Save("archive.cab");
}
See Also
- class CabEntry
- class CabEntrySettings
- class CabArchive
- namespace Aspose.Zip.Cab
- assembly Aspose.Zip