C# ZipArchive CreateEntry(String, CompressionLevel)

Description

ZipArchive CreateEntry(String, CompressionLevel) Creates an empty entry that has the specified entry name and compression level in the zip archive.

Syntax

ZipArchive.CreateEntry(String, CompressionLevel) has the following syntax.


public ZipArchiveEntry CreateEntry(
  string entryName,
  CompressionLevel compressionLevel
)

Parameters

ZipArchive.CreateEntry(String, CompressionLevel) has the following parameters.

  • entryName - A path, relative to the root of the archive, that specifies the name of the entry to be created.
  • compressionLevel - One of the enumeration values that indicates whether to emphasize speed or compression effectiveness when creating the entry.

Returns

ZipArchive.CreateEntry(String, CompressionLevel) method returns An empty entry in the zip archive.

Example

The following example shows how to create an entry with the optimal compression level.


// www  .  ja v  a2  s  . c o  m
using System;
using System.IO;
using System.IO.Compression;

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




















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




DeflateStream
GZipStream
ZipArchive
ZipArchiveEntry
ZipFile
ZipFileExtensions