ZipArchiveEntry Class

.NET Framework (current version)
 

Represents a compressed file within a zip archive.

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

System.Object
  System.IO.Compression.ZipArchiveEntry

public class ZipArchiveEntry

NameDescription
System_CAPS_pubpropertyArchive

Gets the zip archive that the entry belongs to.

System_CAPS_pubpropertyCompressedLength

Gets the compressed size of the entry in the zip archive.

System_CAPS_pubpropertyFullName

Gets the relative path of the entry in the zip archive.

System_CAPS_pubpropertyLastWriteTime

Gets or sets the last time the entry in the zip archive was changed.

System_CAPS_pubpropertyLength

Gets the uncompressed size of the entry in the zip archive.

System_CAPS_pubpropertyName

Gets the file name of the entry in the zip archive.

NameDescription
System_CAPS_pubmethodDelete()

Deletes the entry from the zip archive.

System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodOpen()

Opens the entry from the zip archive.

System_CAPS_pubmethodToString()

Retrieves the relative path of the entry in the zip archive.(Overrides Object.ToString().)

NameDescription
System_CAPS_pubmethodExtractToFile(String)

Overloaded. Extracts an entry in the zip archive to a file.(Defined by ZipFileExtensions.)

System_CAPS_pubmethodExtractToFile(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.)

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.

The methods for manipulating zip archives and their file entries are spread across three classes: ZipFile, ZipArchive and ZipArchiveEntry.

To…

Use…

Create a zip archive from a directory

ZipFile.CreateFromDirectory

Extract the contents of a zip archive to a directory

ZipFile.ExtractToDirectory

Add new files to an existing zip archive

ZipArchive.CreateEntry

Retrieve an file in a zip archive

ZipArchive.GetEntry

Retrieve all of the files in a zip archive

ZipArchive.Entries

To open a stream to an individual file contained in a zip archive

ZipArchiveEntry.Open

Delete a file from a zip archive

ZipArchiveEntry.Delete

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 8.x 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.

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

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

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            using (FileStream zipToOpen = new FileStream(@"c:\users\exampleuser\release.zip", FileMode.Open))
            {
                using (ZipArchive archive = new ZipArchive(zipToOpen, ZipArchiveMode.Update))
                {
                    ZipArchiveEntry readmeEntry = archive.CreateEntry("Readme.txt");
                    using (StreamWriter writer = new StreamWriter(readmeEntry.Open()))
                    {
                            writer.WriteLine("Information about this package.");
                            writer.WriteLine("========================");
                    }
                }
            }
        }
    }
}

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.

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));
                    }
                }
            } 
        }
    }
}

Universal Windows Platform
Available since 8
.NET Framework
Available since 4.5
Portable Class Library
Supported in: portable .NET platforms
Windows Phone
Available since 8.1

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

Return to top
Show: