ArchiveCreateEntry Method (String, String, Boolean, ArchiveEntrySettings)

Create single entry within the archive.

Namespace:  Aspose.Zip
Assembly:  Aspose.Zip (in Aspose.Zip.dll) Version: 22.3
Syntax
public ArchiveEntry CreateEntry(
	string name,
	string path,
	bool openImmediately = false,
	ArchiveEntrySettings newEntrySettings = null
)

Parameters

name
Type: SystemString
The name of the entry.
path
Type: SystemString
The fully qualified name of the new file, or the relative file name to be compressed.
openImmediately (Optional)
Type: SystemBoolean
True if open the file immediately, otherwise open the file on archive saving.
newEntrySettings (Optional)
Type: Aspose.Zip.SavingArchiveEntrySettings
Compression and encryption settings used for added ArchiveEntry item.

Return Value

Type: ArchiveEntry
Zip 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.
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.
NotSupportedExceptionFile at path contains a colon (:) in the middle of the string.
Remarks

The entry name is solely set within name parameter. The file name provided in path parameter does not affect the entry name.

If the file is opened immediately with openImmediately parameter it becomes blocked until archive is saved.

Examples
using (FileStream zipFile = File.Open("archive.zip", FileMode.Create))
{
    using (var archive = new Archive())
    {
        archive.CreateEntry("data.bin", "file.dat");
        archive.Save(zipFile);
    }
}
See Also