CabArchive.CreateEntries

CreateEntries(DirectoryInfo, bool)

Adds to the archive all files, recursively, from the specified directory.

public CabArchive CreateEntries(DirectoryInfo directory, bool includeRootDirectory = true)
ParameterTypeDescription
directoryDirectoryInfoDirectory to compress.
includeRootDirectoryBooleanIndicates whether to include the root directory name in entry paths.

Return Value

The current CabArchive instance.

Exceptions

exceptioncondition
ArgumentNullExceptiondirectory is null.
ObjectDisposedExceptionArchive has been disposed and cannot be used.
DirectoryNotFoundExceptiondirectory cannot be found.
SecurityExceptionThe caller does not have the required permission to access directory or its content.
UnauthorizedAccessExceptionAccess to directory or one of its files is denied.
IOExceptionAn I/O error occurs while accessing directory.
PathTooLongExceptionA generated entry path exceeds the system-defined maximum length.
InvalidOperationExceptionThe archive is prepared for extraction and cannot add entries.

Examples

using (var archive = new CabArchive())
{
    var directory = new DirectoryInfo("logs");
    archive.CreateEntries(directory);
    archive.Save("logs.cab");
}

See Also


CreateEntries(string, bool)

Adds to the archive all files recursively from the specified directory path.

public CabArchive CreateEntries(string sourceDirectory, bool includeRootDirectory = true)
ParameterTypeDescription
sourceDirectoryStringDirectory path to compress.
includeRootDirectoryBooleanIndicates whether to include the root directory name in entry paths.

Return Value

The current CabArchive instance.

Exceptions

exceptioncondition
ObjectDisposedExceptionArchive has been disposed and cannot be used.
ArgumentNullExceptionsourceDirectory is null.
DirectoryNotFoundExceptionsourceDirectory cannot be found.
SecurityExceptionThe caller does not have the required permission to access sourceDirectory.
UnauthorizedAccessExceptionAccess to sourceDirectory is denied.
PathTooLongExceptionThe specified sourceDirectory exceeds the system-defined maximum length.
ArgumentExceptionsourceDirectory is empty, contains only white spaces, or contains invalid characters.
IOExceptionAn I/O error occurs while accessing sourceDirectory.
InvalidOperationExceptionThe archive is prepared for extraction and cannot add entries.

Examples

using (var archive = new CabArchive(new CabEntrySettings(new CabStoreCompressionSettings())))
{
    archive.CreateEntries("data", includeRootDirectory: false);
    archive.Save("stored_data.cab");
}

See Also