CabArchive.CreateEntry

CreateEntry(string, string, CabEntrySettings)

Create a single entry within the archive.

public CabEntry CreateEntry(string name, string path, CabEntrySettings newEntrySettings = null)
ParameterTypeDescription
nameStringThe name of the entry.
pathStringThe fully qualified name of the new file, or the relative file name to be compressed.
newEntrySettingsCabEntrySettingsCompression and encryption settings used for added CabEntry item.

Return Value

Cab entry instance.

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.
ObjectDisposedExceptionArchive has been disposed and cannot be used.
InvalidOperationExceptionThe 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


CreateEntry(string, Stream, CabEntrySettings)

Create a single entry within the archive.

public CabEntry CreateEntry(string name, Stream source, CabEntrySettings newEntrySettings = null)
ParameterTypeDescription
nameStringThe name of the entry.
sourceStreamThe input stream for the entry.
newEntrySettingsCabEntrySettingsCompression and encryption settings used for added CabEntry item.

Return Value

Cab entry instance.

Exceptions

exceptioncondition
ObjectDisposedExceptionArchive has been disposed and cannot be used.
InvalidOperationExceptionThe 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


CreateEntry(string, FileInfo, CabEntrySettings)

Create a single entry within the archive.

public CabEntry CreateEntry(string name, FileInfo fileInfo, 
    CabEntrySettings newEntrySettings = null)
ParameterTypeDescription
nameStringThe name of the entry.
fileInfoFileInfoThe metadata of file to be compressed.
newEntrySettingsCabEntrySettingsCompression and encryption settings used for added CabEntry item.

Return Value

Cab entry instance.

Exceptions

exceptioncondition
UnauthorizedAccessExceptionfileInfo is read-only or is a directory.
DirectoryNotFoundExceptionThe specified path is invalid, such as being on an unmapped drive.
IOExceptionThe file is already open.
FileNotFoundExceptionfileInfo represents a file that cannot be found.
SecurityExceptionThe caller does not have the required permission to access fileInfo.
ObjectDisposedExceptionArchive has been disposed and cannot be used.
InvalidOperationExceptionThe 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