ZipFileExtensions.CreateEntryFromFileAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CreateEntryFromFileAsync(ZipArchive, String, String, CancellationToken) |
Asynchronously adds a file from the file system to the archive under the specified entry name. |
CreateEntryFromFileAsync(ZipArchive, String, String, CompressionLevel, CancellationToken) |
Asynchronously adds a file from the file system to the archive under the specified entry name. |
CreateEntryFromFileAsync(ZipArchive, String, String, CancellationToken)
Asynchronously adds a file from the file system to the archive under the specified entry name.
public static System.Threading.Tasks.Task<System.IO.Compression.ZipArchiveEntry> CreateEntryFromFileAsync(this System.IO.Compression.ZipArchive destination, string sourceFileName, string entryName, System.Threading.CancellationToken cancellationToken = default);
static member CreateEntryFromFileAsync : System.IO.Compression.ZipArchive * string * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.IO.Compression.ZipArchiveEntry>
<Extension()>
Public Function CreateEntryFromFileAsync (destination As ZipArchive, sourceFileName As String, entryName As String, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ZipArchiveEntry)
Parameters
- destination
- ZipArchive
The zip archive to add the file to.
- sourceFileName
- String
The path to the file on the file system to be copied from. The path is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
- entryName
- String
The name of the entry to be created.
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
A wrapper for the newly created entry.
Exceptions
sourceFileName
is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
-or-
entryName
is a zero-length string.
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 be less than 248 characters, and file names must be less than 260 characters.
The specified sourceFileName
is invalid, (for example, it is on an unmapped drive).
An I/O error occurred while opening the file specified by sourceFileName
.
sourceFileName
specified a directory.
-or-
The caller does not have the required permission.
The file specified in sourceFileName
was not found.
sourceFileName
is in an invalid format or the ZipArchive does not support writing.
The ZipArchive has already been closed.
An asynchronous operation is cancelled.
Remarks
The new entry in the archive will contain the contents of the file.
The last write time of the archive entry is set to the last write time of the file on the file system.
If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.
If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name. Since no CompressionLevel
is specified, the default provided by the implementation of the underlying compression algorithm will be used; the ZipArchive
will not impose its own default.
(Currently, the underlying compression algorithm is provided by the DeflateStream class.)
Applies to
CreateEntryFromFileAsync(ZipArchive, String, String, CompressionLevel, CancellationToken)
Asynchronously adds a file from the file system to the archive under the specified entry name.
public static System.Threading.Tasks.Task<System.IO.Compression.ZipArchiveEntry> CreateEntryFromFileAsync(this System.IO.Compression.ZipArchive destination, string sourceFileName, string entryName, System.IO.Compression.CompressionLevel compressionLevel, System.Threading.CancellationToken cancellationToken = default);
static member CreateEntryFromFileAsync : System.IO.Compression.ZipArchive * string * string * System.IO.Compression.CompressionLevel * System.Threading.CancellationToken -> System.Threading.Tasks.Task<System.IO.Compression.ZipArchiveEntry>
<Extension()>
Public Function CreateEntryFromFileAsync (destination As ZipArchive, sourceFileName As String, entryName As String, compressionLevel As CompressionLevel, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ZipArchiveEntry)
Parameters
- destination
- ZipArchive
The zip archive to add the file to.
- sourceFileName
- String
The path to the file on the file system to be copied from. The path is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.
- entryName
- String
The name of the entry to be created.
- compressionLevel
- CompressionLevel
The level of the compression (speed/memory vs. compressed size trade-off).
- cancellationToken
- CancellationToken
The cancellation token to monitor for cancellation requests.
Returns
A wrapper for the newly created entry.
Exceptions
sourceFileName
is a zero-length string, contains only whitespace, or contains one or more invalid characters as defined by InvalidPathChars.
-or-
entryName
is a zero-length string.
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 be less than 248 characters, and file names must be less than 260 characters.
The specified sourceFileName
is invalid, (for example, it is on an unmapped drive).
An I/O error occurred while opening the file specified by sourceFileName
.
sourceFileName
specified a directory.
-or-
The caller does not have the required permission.
The file specified in sourceFileName
was not found.
sourceFileName
is in an invalid format or the ZipArchive does not support writing.
The ZipArchive has already been closed.
An asynchronous operation is cancelled.
Remarks
The new entry in the archive will contain the contents of the file.
The last write time of the archive entry is set to the last write time of the file on the file system.
If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.
If the specified source file has an invalid last modified time, the first datetime representable in the Zip timestamp format (midnight on January 1, 1980) will be used. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.