Export (0) Print
Expand All

ZipArchiveEntry.Open Method

.NET Framework 4.5

Opens the entry from the zip archive.

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

public Stream Open()

Return Value

Type: System.IO.Stream
The stream that represents the contents of the entry.

ExceptionCondition
IOException

The entry is already currently open for writing.

-or-

The entry has been deleted from the archive.

-or-

The archive for this entry was opened with the Create mode, and this entry has already been written to.

InvalidDataException

The entry is either missing from the archive or is corrupt and cannot be read.

-or-

The entry has been compressed by using a compression method that is not supported.

ObjectDisposedException

The zip archive for this entry has been disposed.

You use this method to access the stream for an entry in a zip archive. After retrieving the stream, you can read from or write to the stream. When you write to the stream, the modifications you make to the entry will appear in the zip archive.

The following example shows how to create a new entry, open it with the Open method, and write to the stream.

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("========================");
                    }
                }
            }
        }
    }
}

.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