C# ZipArchive GetEntry

Description

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

Syntax

ZipArchive.GetEntry has the following syntax.


public ZipArchiveEntry GetEntry(
  string entryName
)

Parameters

ZipArchive.GetEntry has the following parameters.

  • entryName - A path, relative to the root of the archive, that identifies the entry to retrieve.

Returns

ZipArchive.GetEntry method returns A wrapper for the specified entry in the archive; null if the entry does not exist in the archive.

Example

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


/*from ww w  .  j  av a2  s  .c om*/
using System;
using System.IO;
using System.IO.Compression;

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




















Home »
  C# Tutorial »
    System.IO.Compression »




DeflateStream
GZipStream
ZipArchive
ZipArchiveEntry
ZipFile
ZipFileExtensions