Export (0) Print
Expand All

ZipArchive.Entries Property

.NET Framework 4.5

Gets the collection of entries that are currently in the zip archive.

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

public ReadOnlyCollection<ZipArchiveEntry> Entries { get; }

Property Value

Type: System.Collections.ObjectModel.ReadOnlyCollection<ZipArchiveEntry>
The collection of entries that are currently in the zip archive.

ExceptionCondition
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.

Use the Entries property to retrieve the entire collection of entries. Use the GetEntry method to retrieve a single entry by name.

The following example shows how to open a zip archive and iterate through the collection of entries.

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string zipPath = @"c:\example\start.zip";
            string extractPath = @"c:\example\extract";

            using (ZipArchive archive = ZipFile.OpenRead(zipPath))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                    {
                        entry.ExtractToFile(Path.Combine(extractPath, entry.FullName));
                    }
                }
            } 
        }
    }
}

.NET Framework

Supported in: 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.

Show:
© 2014 Microsoft