Get Started - Create a ZIP Archive

  • 2 minutes to read
IMPORTANT

You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.

This article describes how to get started with the ZIP compression component for .NET Framework and .NET Core.

Create a .NET Framework Application

  1. Create a new Console Application (.NET Framework) project.

  2. Add a reference to the DevExpress.Docs.v20.2.dll library.

  3. Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).

    using DevExpress.Compression;
    // ...
    
    static void Main(string[] args)
    {
        string zipFileName = "d:\\Test.zip";
        string sourceDir = @"C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data";
        string password = "123";
        EncryptionType encryptionType = EncryptionType.PkZip;
        using (ZipArchive archive = new ZipArchive())
        {
            archive.Password = password;
            archive.EncryptionType = encryptionType;
            archive.AddDirectory(sourceDir);
            archive.Save(zipFileName);
        }
    }
    
  4. Run the project. The code example creates the Test.zip archive with all files encrypted using "123" password.

Create a .NET Core Application

  1. Start Microsoft Visual Studio and create a new Console Application (.NET Core) project.

  2. Install the DevExpress.Document.Processor NuGet package.

  3. Paste the code below in the Main method of the Program.cs file (Main procedure of the Module1.vb file for Visual Basic).

    using DevExpress.Compression;
    // ...
    
    static void Main(string[] args)
    {
        string zipFileName = "d:\\Test.zip";
        string sourceDir = @"C:\Users\Public\Documents\DevExpress Demos 19.2\Components\Data";
        string password = "123";
        EncryptionType encryptionType = EncryptionType.PkZip;
        using (ZipArchive archive = new ZipArchive())
        {
            archive.Password = password;
            archive.EncryptionType = encryptionType;
            archive.AddDirectory(sourceDir);
            archive.Save(zipFileName);
        }
    }
    
  4. Run the project. The code example creates the Test.zip archive with all files encrypted using "123" password.

See Also