Export (0) Print
Expand All

ZipArchive.GetEntry Method

.NET Framework 4.6 and 4.5

Retrieves a wrapper for the specified entry in the zip archive.

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

'Declaration
Public Function GetEntry ( _
	entryName As String _
) As ZipArchiveEntry

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.ZipArchiveEntry
A wrapper for the specified entry in the archive; Nothing if the entry does not exist in the archive.

ExceptionCondition
ArgumentException

entryName is Empty.

ArgumentNullException

entryName is Nothing.

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.

If multiple entries that have the specified name exist in the archive, the first one is returned. The name of the entry is compared to entryName using ordinal comparison.

The following example shows how to use the GetEntry method to retrieve an entry.

Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Dim zipPath As String = "c:\example\result.zip" 

        Using archive As ZipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update)
            Dim entry As ZipArchiveEntry = archive.GetEntry("ExistingFile.txt")

            Using writer As StreamWriter = New StreamWriter(entry.Open())
                writer.BaseStream.Seek(0, SeekOrigin.End)
                writer.WriteLine("append line to file")
            End Using
            entry.LastWriteTime = DateTimeOffset.UtcNow.LocalDateTime
        End Using 
    End Sub 

End Module

.NET Framework

Supported in: 4.6, 4.5

Supported in: Windows Phone 8.1
Show:
© 2015 Microsoft