Search Results for

    Show / Hide Table of Contents

    Class IronZipArchive

    An IronZipArchive for ZIP-type ".zip" Archives

    Inheritance
    System.Object
    IronBaseArchive
    IronZipArchive
    Implements
    System.IDisposable
    Inherited Members
    IronBaseArchive._storedArchivePath
    IronBaseArchive._internalStream
    IronBaseArchive.isDisposed
    Namespace: IronZip
    Assembly: IronZip.dll
    Syntax
    public class IronZipArchive : IronBaseArchive

    IronZipArchive creates, reads, edits, and extracts ZIP (.zip) archives from C#. Start an empty archive with new IronZipArchive(), or open an existing one by passing a file path, a Stream, or a byte[] to a constructor (each accepts an optional password). Static factories cover the common starting points: FromFile, FromFiles, FromDirectory, and FromArchive. The type derives from IronBaseArchive and is disposable, so wrap it in a using statement.

    The members group into four jobs. Building an archive uses Add and AddArchiveEntry to put files in. Editing uses Delete, ReplaceEntry, Contains, the Count property, and Entries(), which returns a List<Entry> describing each file. Securing uses Encrypt and SetPassword with an EncryptionMethods value, RemoveEncryption, or the ZipSaveOptions property for password and compression in one object. Output uses Save, SaveAs, and the static ExtractArchiveToDirectory to unpack an archive to disk.

    A typical run constructs an archive, adds files, and saves. Set Comment to label the archive, adjust Compression for the size and speed trade-off, and call Encrypt before saving when the contents need protection. Because each Add takes one path, call it once per file or build from a directory with FromDirectory. Opening an existing archive through a path constructor lets you add or remove entries and call Save to write the changes back in place, while SaveAs writes to a new path; pass a password to that constructor to open an encrypted archive.

    using IronZip;
    
    using var archive = new IronZipArchive();
    archive.Add("report.pdf");
    archive.Add("image.png");
    archive.SaveAs("output.zip");

    The create ZIP example and extract ZIP example show the round trip, and the create, read, and extract tutorial walks through a complete project.

    Constructors

    IronZipArchive(Byte[], String)

    Open an existing protected Archive. Please use in a using block. Use the SaveAs method to export the archive.

    Declaration
    public IronZipArchive(byte[] Bytes, string Password = null)
    Parameters
    Type Name Description
    System.Byte[] Bytes

    Byte[] containing the existing archive.

    System.String Password

    Password for opening the protected archive.

    IronZipArchive(Int32)

    Creating an empty archive. Please use in a using block. Use the SaveAs method to export the archive.

    Declaration
    public IronZipArchive(int Compression = 9)
    Parameters
    Type Name Description
    System.Int32 Compression

    Optionally sets the compression level. 0 is the weakest, 9 is the highest compression, with 9 as the default value.

    IronZipArchive(Stream, String)

    Open an existing protected Archive. Please use in a using block. Use the SaveAs method to export the archive.

    Declaration
    public IronZipArchive(Stream StreamPath, string Password = null)
    Parameters
    Type Name Description
    System.IO.Stream StreamPath

    Stream containing the existing archive.

    System.String Password

    Password for opening the protected archive.

    IronZipArchive(String, String)

    Open an existing Archive. Please use in a using block. Use the SaveAs method to export the archive.

    Declaration
    public IronZipArchive(string ArchivePath, string Password = null)
    Parameters
    Type Name Description
    System.String ArchivePath

    File path to open the existing Archive. Example:

    a.zip
    You may use an absolute path.

    System.String Password

    Password for opening the protected archive.

    Properties

    Comment

    Sets/Gets the comment for the entire archive.

    Declaration
    public string Comment { get; set; }
    Property Value
    Type Description
    System.String

    Count

    Retrieves the total number of entries in the archive.

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

    The count of entries within the archive.

    ZipSaveOptions

    Set the security settings for Zip Archive

    Declaration
    public ZipSaveOptions ZipSaveOptions { get; set; }
    Property Value
    Type Description
    ZipSaveOptions

    Methods

    Add(String)

    Adds an archive entry (file) to the Archive. These entries will appear as files when the Archive is extracted.

    Declaration
    public void Add(string EntryFilePath)
    Parameters
    Type Name Description
    System.String EntryFilePath

    Filepath to the archive entry to add

    AddArchiveEntry(String)

    Adds an archive entry (file) to the Archive. These entries will appear as files when the Archive is extracted.

    Declaration
    public void AddArchiveEntry(string EntryFilePath)
    Parameters
    Type Name Description
    System.String EntryFilePath

    Filepath to the archive entry to add

    Compression(Int32)

    Sets the compression level (default is 9).

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

    0 is weakest, 9 is highest compression. 9 is default.

    Contains(String)

    Checks if an entry with the specified name exists in the archive.

    Declaration
    public bool Contains(string EntryName)
    Parameters
    Type Name Description
    System.String EntryName

    The name of the entry to check for existence.

    Returns
    Type Description
    System.Boolean

    true if an entry with the specified name exists in the archive; otherwise, false.

    Delete(String)

    Deletes an entry from the archive.

    Declaration
    public void Delete(string EntryName)
    Parameters
    Type Name Description
    System.String EntryName

    The name of the entry to be deleted.

    Dispose()

    Check the license before using IronZIP

    Declaration
    public override void Dispose()
    Overrides
    IronBaseArchive.Dispose()
    Exceptions
    Type Condition
    IronSoftware.Exceptions.LicensingException

    Encrypt(String, EncryptionMethods)

    Sets the password for a specific encryption method.

    Declaration
    public void Encrypt(string Password, EncryptionMethods EncryptionMethods)
    Parameters
    Type Name Description
    System.String Password

    The password to set.

    EncryptionMethods EncryptionMethods

    The encryption method to use. Supported types are traditional, AES128, and AES256.

    Entries()

    Load the entries of an existing Archive

    Declaration
    public List<Entry> Entries()
    Returns
    Type Description
    System.Collections.Generic.List<Entry>

    ExtractArchiveToDirectory(String, String, String)

    Will load an Archive and extract it to a Directory (System Folder)

    Declaration
    public static void ExtractArchiveToDirectory(string ArchiveSourcePath, string SaveDirectoryPath, string Password = null)
    Parameters
    Type Name Description
    System.String ArchiveSourcePath

    Path to the Archive to extract

    System.String SaveDirectoryPath

    Directory to extract files to

    System.String Password

    Optional password to open the archive

    FromArchive(String, String)

    Creates an instance of IronZipArchive from an existing archive.

    Declaration
    public static IronZipArchive FromArchive(string ArchivePath, string Password = null)
    Parameters
    Type Name Description
    System.String ArchivePath

    The path to the existing archive.

    System.String Password

    The password for decryption (null if not encrypted).

    Returns
    Type Description
    IronZipArchive

    An instance of IronZipArchive representing the specified archive.

    FromDirectory(String, Int32)

    Declaration
    public static IronZipArchive FromDirectory(string DirectoryPath, int Compression = 9)
    Parameters
    Type Name Description
    System.String DirectoryPath
    System.Int32 Compression
    Returns
    Type Description
    IronZipArchive

    FromFile(String, Int32)

    Creates an Archive with a specific file to add to it. Please use in a using block. Use the SaveAs method to export the archive.

    Declaration
    public static IronZipArchive FromFile(string FilePath, int Compression = 9)
    Parameters
    Type Name Description
    System.String FilePath

    File Entry to add to the Archive

    System.Int32 Compression

    Optionally set the compression level. 0 is weakest, 9 is highest compression. 9 is default.

    Returns
    Type Description
    IronZipArchive

    Returns the constructed IronZipArchive with the file entry added.

    FromFiles(String[], Int32)

    Creates an Archive with some files to add to it. Please use in a using block. Use the SaveAs method to export the archive.

    Declaration
    public static IronZipArchive FromFiles(string[] Paths, int Compression = 9)
    Parameters
    Type Name Description
    System.String[] Paths

    File Entries to add to the Archive

    System.Int32 Compression

    Optionally set the compression level. 0 is weakest, 9 is highest compression. 9 is default.

    Returns
    Type Description
    IronZipArchive

    Returns the constructed IronZipArchive with the file entries added.

    RemoveEncryption()

    Remove the encryption password from the zip archive.

    Declaration
    public void RemoveEncryption()

    ReplaceEntry(String, String)

    Replaces an entry within the archive with a new one.

    Declaration
    public void ReplaceEntry(string OldEntry, string NewEntry)
    Parameters
    Type Name Description
    System.String OldEntry

    The name of the entry to be replaced.

    System.String NewEntry

    The name of the new entry to replace the existing one.

    Save()

    Save the archive

    Declaration
    public override void Save()
    Overrides
    IronBaseArchive.Save()
    Remarks

    Users cannot add additional entries after saving

    Save(ZipSaveOptions)

    Save the archive

    Declaration
    public void Save(ZipSaveOptions ZipSaveOptions = null)
    Parameters
    Type Name Description
    ZipSaveOptions ZipSaveOptions

    Options for IronZipArchive

    Remarks

    Users cannot add additional entries after saving

    SaveAs(String)

    Save the archive to the specified path

    Declaration
    public override void SaveAs(string Path)
    Parameters
    Type Name Description
    System.String Path

    Save path

    Overrides
    IronBaseArchive.SaveAs(String)
    Remarks

    Users cannot add additional entries after saving

    SaveAs(String, ZipSaveOptions)

    Save the archive to the specified path

    Declaration
    public void SaveAs(string Path, ZipSaveOptions ZipSaveOptions = null)
    Parameters
    Type Name Description
    System.String Path

    Save path

    ZipSaveOptions ZipSaveOptions

    Options for IronZipArchive

    Remarks

    Users cannot add additional entries after saving

    SetPassword(String, EncryptionMethods)

    Sets the password for a specific encryption method.

    Declaration
    public void SetPassword(string Password, EncryptionMethods EncryptionMethods)
    Parameters
    Type Name Description
    System.String Password

    The password to set.

    EncryptionMethods EncryptionMethods

    The encryption method to use. Supported types are traditional, AES128, and AES256.

    Implements

    System.IDisposable

    Inherited members

    _storedArchivePath
    _internalStream
    isDisposed
    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet
    IronZIP_for_dotnet_log2o
    Blue key in circleGet started for FREE
    No credit card required
    Test in a live environment

    Test in production without watermarks.
    Works wherever you need it to.

    Fully-functional product

    Get 30 days of fully functional product.
    Have it up and running in minutes.

    24/5 technical support

    Full access to our support engineering team during your product trial

    Grey key in circleGet started for FREE
    The trial form was submitted successfully.
    Calendar in circleBook Free Live Demo
    No contact, no card details, no commitments Book a 30-minute, personal demo.
    Here's what to expect:

    A live demo of our product and its key features

    Get project specific feature recommendations

    All your questions are answered to make sure you have all the information you need. (No commitment whatsoever.)

    Grey key in circleBook Free Live Demo
    Your booking has been completed Check your e-mail for confirmation
    Support Team Member 6 related to The C# PDF Library Support Team Member 14 related to The C# PDF Library Support Team Member 4 related to The C# PDF Library Support Team Member 2 related to The C# PDF Library
    Online 24/5
    Need help? Our sales team would be glad to help you.
    Try the Enterprise Trial
    ironpdf_for_dotnet_log2o
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    bullet_checkedNo credit card or account creation required
    Key in blue circle
    Get your free 30-day Trial Key instantly.
    Blue key in circleNo credit card or account creation required
    Green Check in orange circle
    The trial form was submitted successfully.
    badge_greencheck_in_yellowcircle
    Thank you for starting a trial

    Please check your email for the trial license key.

    If you don’t receive an email, please start a live chat or email support@ironsoftware.com

    Install with NuGet
    View Licensing
    • Logo Aetna
    • Logo NASA
    • Logo GE
    • Logo Porsche
    • Logo USDA
    • Logo Qatar
    Join Millions of Engineers who’ve tried IronZIP