menu

WinForms

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class ZipArchive - WindowsForms API Reference | Syncfusion

    Show / Hide Table of Contents

    Class ZipArchive

    Represents zip archive.

    Inheritance
    System.Object
    ZipArchive
    Implements
    System.IDisposable
    Inherited Members
    System.Object.Equals(System.Object)
    System.Object.Equals(System.Object, System.Object)
    System.Object.GetHashCode()
    System.Object.GetType()
    System.Object.MemberwiseClone()
    System.Object.ReferenceEquals(System.Object, System.Object)
    System.Object.ToString()
    Namespace: Syncfusion.Compression.Zip
    Assembly: Syncfusion.Compression.Base.dll
    Syntax
    public class ZipArchive : IDisposable

    Constructors

    ZipArchive()

    Declaration
    public ZipArchive()

    Fields

    CreateCompressor

    Creates compressor.

    Declaration
    public ZipArchive.CompressorCreator CreateCompressor
    Field Value
    Type
    ZipArchive.CompressorCreator

    Properties

    CheckCrc

    Indicates whether we should check Crc value when reading item's data. Check is performed when user gets access to item's decompressed data for the first time.

    Declaration
    public bool CheckCrc { get; set; }
    Property Value
    Type
    System.Boolean

    Count

    Returns number of items inside archive. Read-only.

    Declaration
    public int Count { get; }
    Property Value
    Type
    System.Int32

    DefaultCompressionLevel

    Gets / sets default compression level - compression level for new items. By default is equal to CompressionLevel.Best.

    Declaration
    public CompressionLevel DefaultCompressionLevel { get; set; }
    Property Value
    Type
    CompressionLevel

    EncryptionAlgorithm

    Returns the encryption algorithm used. Default value is NONE.

    Declaration
    public EncryptionAlgorithm EncryptionAlgorithm { get; }
    Property Value
    Type
    EncryptionAlgorithm

    FileNamePreprocessor

    Gets / sets file name preprocessor - object that converts full file/folder name into value that will be written into zip archive.

    Declaration
    public IFileNamePreprocessor FileNamePreprocessor { get; set; }
    Property Value
    Type
    IFileNamePreprocessor

    Item[Int32]

    Returns single archive item from the collection. Read-only.

    Declaration
    public ZipArchiveItem this[int index] { get; }
    Parameters
    Type Name Description
    System.Int32 index

    Zero-based index of the item to return.

    Property Value
    Type Description
    ZipArchiveItem

    Single archive item from the collection.

    Item[String]

    Returns item by its name. Null if item wasn't found. Read-only.

    Declaration
    public ZipArchiveItem this[string itemName] { get; }
    Parameters
    Type Name Description
    System.String itemName
    Property Value
    Type
    ZipArchiveItem

    Items

    Returns the items inside archive. Read-only.

    Declaration
    public ZipArchiveItem[] Items { get; }
    Property Value
    Type
    ZipArchiveItem[]

    UseNetCompression

    Uses custom compressed stream reader and writer.

    Declaration
    public bool UseNetCompression { get; set; }
    Property Value
    Type
    System.Boolean

    Methods

    AddDirectory(String)

    Adds empty directory to the archive.

    Declaration
    public ZipArchiveItem AddDirectory(string directoryName)
    Parameters
    Type Name Description
    System.String directoryName

    Directory path.

    Returns
    Type Description
    ZipArchiveItem

    Item that has been added.

    AddFile(String)

    Adds specified file to the archive.

    Declaration
    public ZipArchiveItem AddFile(string fileName)
    Parameters
    Type Name Description
    System.String fileName

    File to add.

    Returns
    Type Description
    ZipArchiveItem

    Item that has been added.

    AddFile(String, String)

    Adds the specified file to the zip archive with the password.

    Declaration
    public ZipArchiveItem AddFile(string fileName, string password)
    Parameters
    Type Name Description
    System.String fileName

    File to add.

    System.String password

    File password

    Returns
    Type Description
    ZipArchiveItem

    Item that has been added.

    AddItem(ZipArchiveItem)

    Adds existing item to the archive.

    Declaration
    public ZipArchiveItem AddItem(ZipArchiveItem item)
    Parameters
    Type Name Description
    ZipArchiveItem item

    Item to add.

    Returns
    Type Description
    ZipArchiveItem

    Added item.

    AddItem(String, Stream, Boolean, FileAttributes)

    Adds new item to the archive

    Declaration
    public ZipArchiveItem AddItem(string itemName, Stream data, bool bControlStream, FileAttributes attributes)
    Parameters
    Type Name Description
    System.String itemName

    Item name to add.

    System.IO.Stream data

    Items data stream (can be null for empty files or folders).

    System.Boolean bControlStream

    Indicates whether ZipArchive is responsible for stream closing.

    System.IO.FileAttributes attributes

    File attributes.

    Returns
    Type Description
    ZipArchiveItem

    Item that has been added.

    AddItem(String, Stream, Boolean, FileAttributes, String)

    Adds a new item in the zip archive with the specified name and password.

    Declaration
    public ZipArchiveItem AddItem(string itemName, Stream data, bool bControlStream, FileAttributes attributes, string password)
    Parameters
    Type Name Description
    System.String itemName

    Item name to add.

    System.IO.Stream data

    Items data stream (can be null for empty files or folders).

    System.Boolean bControlStream

    Indicates whether ZipArchive is responsible for stream closing.

    System.IO.FileAttributes attributes

    File attributes.

    System.String password

    Item or file password

    Returns
    Type Description
    ZipArchiveItem

    Item that has been added.

    Clone()

    Creates a copy of the current instance.

    Declaration
    public ZipArchive Clone()
    Returns
    Type Description
    ZipArchive

    A copy of the current instance.

    Close()

    Clears all internal data.

    Declaration
    public void Close()

    Dispose()

    A method to release allocated unmanaged resources.

    Declaration
    public void Dispose()

    Finalize()

    Class finilizer.

    Declaration
    protected void Finalize()

    Find(String)

    Searches for the item with specified name.

    Declaration
    public int Find(string itemName)
    Parameters
    Type Name Description
    System.String itemName

    Item to find.

    Returns
    Type Description
    System.Int32

    Zero-based item index if found; -1 otherwise.

    Find(Regex)

    Searches for the item with specified name.

    Declaration
    public int Find(Regex itemRegex)
    Parameters
    Type Name Description
    System.Text.RegularExpressions.Regex itemRegex

    Regular expression that defines item to find.

    Returns
    Type Description
    System.Int32

    Zero-based item index if found; -1 otherwise.

    FindValueFromEnd(Stream, UInt32, Int32)

    Searches for integer value from the end of the stream.

    Declaration
    [CLSCompliant(false)]
    public static long FindValueFromEnd(Stream stream, uint value, int maxCount)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Stream to search value in.

    System.UInt32 value

    Value to locate.

    System.Int32 maxCount

    Maximum number of bytes to scan.

    Returns
    Type Description
    System.Int64

    Offset to the value, or -1 if it wasn't found.

    Open(Stream, Boolean)

    Reads archive data from the stream. In the current implementation stream must be seekable and readable to extract data.

    Declaration
    public void Open(Stream stream, bool closeStream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Stream to read data from.

    System.Boolean closeStream

    Indicates whether method should close stream after reading.

    Open(Stream, Boolean, String)

    Reads archive data from the stream. In the current implementation stream must be seekable and readable to extract data.

    Declaration
    public void Open(Stream stream, bool closeStream, string password)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Stream to read data from.

    System.Boolean closeStream

    Indicates whether method should close stream after reading.

    System.String password

    Password for the file to open.

    Open(String)

    Reads archive data from the file.

    Declaration
    public void Open(string inputFileName)
    Parameters
    Type Name Description
    System.String inputFileName

    Filename to read.

    Open(String, String)

    Opens an encrypted zip file with password.

    Declaration
    public void Open(string fileName, string password)
    Parameters
    Type Name Description
    System.String fileName

    File Name.

    System.String password

    Password of the file to open.

    Protect(String, EncryptionAlgorithm)

    Protects the archived file with password using specified algorithm.

    Declaration
    public void Protect(string password, EncryptionAlgorithm type)
    Parameters
    Type Name Description
    System.String password

    Password to protect.

    EncryptionAlgorithm type

    Type of encryption algorithm to be used.

    ReadInt16(Stream)

    Extracts Int16 value from the stream.

    Declaration
    public static short ReadInt16(Stream stream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Stream to read data from.

    Returns
    Type Description
    System.Int16

    Extracted value.

    ReadInt32(Stream)

    Extracts Int32 value from the stream.

    Declaration
    public static int ReadInt32(Stream stream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Stream to read data from.

    Returns
    Type Description
    System.Int32

    Extracted value.

    ReadUInt16(Stream)

    Extracts unsigned Int16 value from the stream.

    Declaration
    public static ushort ReadUInt16(Stream stream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Stream to read data from.

    Returns
    Type Description
    System.UInt16

    Extracted value.

    Remove(Regex)

    Removes items that matches specified regular expression from the collection.

    Declaration
    public void Remove(Regex mask)
    Parameters
    Type Name Description
    System.Text.RegularExpressions.Regex mask

    Regular expression used to decide whether to remove item or not.

    RemoveAt(Int32)

    Removes item at the specified position.

    Declaration
    public void RemoveAt(int index)
    Parameters
    Type Name Description
    System.Int32 index

    Item index to remove.

    RemoveItem(String)

    Removes item from the archive.

    Declaration
    public void RemoveItem(string itemName)
    Parameters
    Type Name Description
    System.String itemName

    Item name to remove.

    Save(Stream, Boolean)

    Saves archive into specified stream.

    Declaration
    public void Save(Stream stream, bool closeStream)
    Parameters
    Type Name Description
    System.IO.Stream stream

    Output stream.

    System.Boolean closeStream

    Indicates whether method should close stream after saving.

    Save(String)

    Saves archive into specified file.

    Declaration
    public void Save(string outputFileName)
    Parameters
    Type Name Description
    System.String outputFileName

    Output file name.

    Save(String, Boolean)

    Saves archive into specified file.

    Declaration
    public void Save(string outputFileName, bool createFilePath)
    Parameters
    Type Name Description
    System.String outputFileName

    Output file name.

    System.Boolean createFilePath

    Indicates whether we should create full path to the file if it doesn't exist.

    UnProtect()

    Removes password from the compressed file.

    Declaration
    public void UnProtect()

    UpdateItem(String, Byte[])

    Updates item inside existing archive.

    Declaration
    public void UpdateItem(string itemName, byte[] newData)
    Parameters
    Type Name Description
    System.String itemName

    Item name to update.

    System.Byte[] newData

    New data for the item.

    UpdateItem(String, Stream, Boolean)

    Updates item inside existing archive.

    Declaration
    public void UpdateItem(string itemName, Stream newDataStream, bool controlStream)
    Parameters
    Type Name Description
    System.String itemName

    Item name to update.

    System.IO.Stream newDataStream

    New data for the item.

    System.Boolean controlStream

    Indicates whether item should control its stream after update.

    UpdateItem(String, Stream, Boolean, FileAttributes)

    Updates existing item or creates new one.

    Declaration
    public void UpdateItem(string itemName, Stream newDataStream, bool controlStream, FileAttributes attributes)
    Parameters
    Type Name Description
    System.String itemName

    Item to update or create.

    System.IO.Stream newDataStream

    New data for the item.

    System.Boolean controlStream

    Indicates whether item should control its stream after update.

    System.IO.FileAttributes attributes

    File attributes for the item. This argument is only used if item is created.

    Events

    OnZipArchiveItemPasswordNeeded

    An event is raised when a unique password is required for the ZipArchiveItem. The event provides the file name and expects the handler to supply the password.

    Declaration
    public event ZipArchive.ZipArchiveItemPasswordEventHandler OnZipArchiveItemPasswordNeeded
    Event Type
    Type
    ZipArchive.ZipArchiveItemPasswordEventHandler

    Implements

    System.IDisposable
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved