Export (0) Print
Expand All

ZipArchiveEntry Class

.NET Framework 4.5

Represents a compressed file within a zip archive.

System.Object
  System.IO.Compression.ZipArchiveEntry

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

'Declaration
Public Class ZipArchiveEntry

The ZipArchiveEntry type exposes the following members.

  NameDescription
Public propertySupported in .NET for Windows Store appsArchiveGets the zip archive that the entry belongs to.
Public propertySupported in .NET for Windows Store appsCompressedLengthGets the compressed size of the entry in the zip archive.
Public propertySupported in .NET for Windows Store appsFullNameGets the relative path of the entry in the zip archive.
Public propertySupported in .NET for Windows Store appsLastWriteTimeGets or sets the last time the entry in the zip archive was changed.
Public propertySupported in .NET for Windows Store appsLengthGets the uncompressed size of the entry in the zip archive.
Public propertySupported in .NET for Windows Store appsNameGets the file name of the entry in the zip archive.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsDeleteDeletes the entry from the zip archive.
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsOpenOpens the entry from the zip archive.
Public methodSupported in .NET for Windows Store appsToStringRetrieves the relative path of the entry in the zip archive. (Overrides Object.ToString.)
Top

  NameDescription
Public Extension MethodExtractToFile(String)Overloaded. Extracts an entry in the zip archive to a file. (Defined by ZipFileExtensions.)
Public Extension MethodExtractToFile(String, Boolean)Overloaded. Extracts an entry in the zip archive to a file, and optionally overwrites an existing file that has the same name. (Defined by ZipFileExtensions.)
Top

A zip archive contains an entry for each compressed file. The ZipArchiveEntry class enables you to examine the properties of an entry, and open or delete the entry. When you open an entry, you can modify the compressed file by writing to the stream for that compressed file. You open an entry by calling the Open method.

If you reference the System.IO.Compression.FileSystem assembly in your project, you can access two extension methods for the ZipArchiveEntry class. Those methods are ExtractToFile(ZipArchiveEntry, String) and ExtractToFile(ZipArchiveEntry, String, Boolean), and they enable you to decompress the contents of the entry to a file. The System.IO.Compression.FileSystem assembly is not available in Windows 8. In Windows Store apps, you can decompress the contents of an archive by using DeflateStream or GZipStream, or you can use the Windows Runtime types Compressor and Decompressor to compress and decompress files.

You can retrieve an entry either by iterating through the Entries collection in ZipArchive, or by calling the GetEntry method in ZipArchive. You can create a new entry by calling CreateEntry or CreateEntryFromFile.

The first example shows how to create a new entry in a zip archive and write to it.

Imports System.IO
Imports System.IO.Compression

Module Module1

    Sub Main()
        Using zipToOpen As FileStream = New FileStream("c:\users\exampleuser\release.zip", FileMode.Open)
            Using archive As ZipArchive = New ZipArchive(zipToOpen, ZipArchiveMode.Update)
                Dim readmeEntry As ZipArchiveEntry = archive.CreateEntry("Readme.txt")
                Using writer As StreamWriter = New StreamWriter(readmeEntry.Open())
                    writer.WriteLine("Information about this package.")
                    writer.WriteLine("========================")
                End Using 
            End Using 
        End Using 
    End Sub 

End Module

The second example shows how to use the ExtractToFile(ZipArchiveEntry, String) extension method. You must reference the System.IO.Compression.FileSystem assembly in your project for the code to execute.

Imports System.IO
Imports System.IO.Compression

Module Module1

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

        Using archive As ZipArchive = ZipFile.OpenRead(zipPath)
            For Each entry As ZipArchiveEntry In archive.Entries
                If entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) Then
                    entry.ExtractToFile(Path.Combine(extractPath, entry.FullName))
                End If 
            Next 
        End Using 
    End Sub 

End Module

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1

Windows Phone 8.1, Windows 8.1, Windows Server 2012 R2, 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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft