Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ZipArchiveMode Enumeration

.NET Framework 4.6 and 4.5

Specifies values for interacting with zip archive entries.

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

public enum ZipArchiveMode

Member nameDescription
CreateOnly creating new archive entries is permitted.
ReadOnly reading archive entries is permitted.
UpdateBoth read and write operations are permitted for archive entries.

When you set the mode to Read, the underlying file or stream must support reading, but does not have to support seeking. If the underlying file or stream supports seeking, the files are read from the archive as they are requested. If the underlying file or stream does not support seeking, the entire archive is held in memory.

When you set the mode to Create, the underlying file or stream must support writing, but does not have to support seeking. Each entry in the archive can be opened only once for writing. If you create a single entry, the data is written to the underlying stream or file as soon as it is available. If you create multiple entries, such as by calling the CreateFromDirectory method, the data is written to the underlying stream or file after all the entries are created.

When you set the mode to Update, the underlying file or stream must support reading, writing, and seeking. The content of the entire archive is held in memory, and no data is written to the underlying file or stream until the archive is disposed.

The following methods include a parameter named mode that lets you specify the archive mode:

The following example shows how to specify a ZipArchiveMode value when creating a ZipArchive object.

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.6, 4.5

.NET for Windows Phone apps

Supported in: Windows Phone 8.1
Show:
© 2015 Microsoft