ZipFileExtensions.ExtractToFile Method (ZipArchiveEntry, String, Boolean)
Extracts an entry in the zip archive to a file, and optionally overwrites an existing file that has the same name.
Namespace: System.IO.Compression
Assembly: System.IO.Compression.FileSystem (in System.IO.Compression.FileSystem.dll)
static member ExtractToFile : source:ZipArchiveEntry * destinationFileName:string * overwrite:bool -> unit
Parameters
- source
- Type: System.IO.Compression.ZipArchiveEntry
The zip archive entry to extract a file from.
- destinationFileName
- Type: System.String
The path of the file to create from the contents of the entry. You can specify either a relative or an absolute path. A relative path is interpreted as relative to the current working directory.
- overwrite
- Type: System.Boolean
true to overwrite an existing file that has the same name as the destination file; otherwise, false.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type ZipArchiveEntry. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).| Exception | Condition |
|---|---|
| ArgumentException | destinationFileName is a zero-length string, contains only white space, or contains one or more invalid characters as defined by InvalidPathChars. -or- destinationFileName specifies a directory. |
| ArgumentNullException | destinationFileName is a null reference (Nothing in Visual Basic). |
| PathTooLongException | 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. |
| DirectoryNotFoundException | The specified path is invalid (for example, it is on an unmapped drive). |
| IOException | destinationFileName already exists and overwrite is false. -or- An I/O error occurred. -or- The entry is currently open for writing. -or- The entry has been deleted from the archive. |
| UnauthorizedAccessException | The caller does not have the required permission to create the new file. |
| InvalidDataException | The entry is missing from the archive or is corrupt and cannot be read. -or- The entry has been compressed by using a compression method that is not supported. |
| ObjectDisposedException | The zip archive that this entry belongs to has been disposed. |
| NotSupportedException | destinationFileName is in an invalid format. -or- The zip archive for this entry was opened in Create mode, which does not permit the retrieval of entries. |
The last write time of the file is set to the last time the entry in the zip archive was changed; this value is stored in the LastWriteTime property.
You cannot use this method to extract a directory; use the ExtractToDirectory method instead.
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.