ZipFileExtensions::CreateEntryFromFile Method (ZipArchive^, String^, String^)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Archives a file by compressing it and adding it to the zip archive.

Namespace:   System.IO.Compression
Assembly:  System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)

static ZipArchiveEntry^ CreateEntryFromFile(
	ZipArchive^ destination,
	String^ sourceFileName,
	String^ entryName


Type: System.IO.Compression::ZipArchive^

The zip archive to add the file to.

Type: System::String^

The path to the file to be archived. You can specify either a relative or an absolute path. A relative path is interpreted as relative to the current working directory.

Type: System::String^

The name of the entry to create in the zip archive.

Return Value

Type: System.IO.Compression::ZipArchiveEntry^

A wrapper for the new entry in the zip archive.

Exception Condition

sourceFileName is Empty, contains only white space, or contains at least one invalid character.


entryName is Empty.


sourceFileName or entryName is null.


In sourceFileName, the specified path, file name, or both exceed the system-defined maximum length. For example, on Windows-based platforms, paths must not exceed 248 characters, and file names must not exceed 260 characters.


sourceFileName is invalid (for example, it is on an unmapped drive).


The file specified by sourceFileName cannot be opened.


sourceFileName specifies a directory.


The caller does not have the required permission to access the file specified by sourceFileName.


The file specified by sourceFileName is not found.


The sourceFileName parameter is in an invalid format.


The zip archive does not support writing.


The zip archive has been disposed.

The new entry in the archive contains the contents of the file specified by sourceFileName. If an entry with the specified name (entryName) already exists in the archive, a second entry is created with an identical name. The LastWriteTime property of the entry is set to the last time the file on the file system was changed.

The following example shows how to create a new entry in a zip archive from an existing file.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 4.5
Return to top