ZipArchive.GetEntry Method
Retrieves a wrapper for the specified entry in the zip archive.
Namespace: System.IO.Compression
Assembly: System.IO.Compression (in System.IO.Compression.dll)
Parameters
- entryName
- Type: System.String
A path, relative to the root of the archive, that identifies the entry to retrieve.
Return Value
Type: System.IO.Compression.ZipArchiveEntryA wrapper for the specified entry in the archive; null if the entry does not exist in the archive.
| Exception | Condition |
|---|---|
| ArgumentException | entryName is Empty. |
| ArgumentNullException | entryName is null. |
| NotSupportedException | The zip archive does not support reading. |
| ObjectDisposedException | The zip archive has been disposed. |
| InvalidDataException | The zip archive is corrupt, and its entries cannot be retrieved. |
The following example shows how to use the GetEntry method to retrieve an entry.
using System; using System.IO; using System.IO.Compression; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { string zipPath = @"c:\example\result.zip"; using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Update)) { ZipArchiveEntry entry = archive.GetEntry("ExistingFile.txt"); using (StreamWriter writer = new StreamWriter(entry.Open())) { writer.BaseStream.Seek(0, SeekOrigin.End); writer.WriteLine("append line to file"); } entry.LastWriteTime = DateTimeOffset.UtcNow.LocalDateTime; } } } }
- 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.