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.
Perform the steps below to get started with the Zip Compression and Archive API.
Create a new Console Application (.NET Framework) project.
Add a reference to the DevExpress.Docs.v19.2.dll library.
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); } }
Run the project. The code example creates the Test.zip archive with all files encrypted using “123” password.
Start Microsoft Visual Studio and create a new Console Application (.NET Core) project.
Install the DevExpress.WindowsDesktop.Document.Processor NuGet package.
Right-click the project in the Solution Explorer and select Edit Project File.
Change the project’s SDK attribute to Microsoft.NET.Sdk.WindowsDesktop and set the UseWindowsForms option to true.
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.0</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup> </Project>
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); } }
Run the project. The code example creates the Test.zip archive with all files encrypted using “123” password.