This basic article explains how to create 7z archive in C#. It includes the detailed steps and code sample to demonstrate how using C# 7z file can be created in your applications. Moreover, we do not need to install any third-party tool or compression application to work with this feature.
Steps to Create 7z Archive in C#
- Install Aspose.ZIP from the NuGet package manager to create 7z archive
- Initialize a SevenZipArchive class object
- Add all files and directories using the CreateEntries method
- Save the output archive as a 7z file
We can clearly understand the process to create a 7z archive through this step-by-step approach. The above steps also cover the configuration details and then provide the C# 7zip example code to create the archive. You can compress a single file by specifying its name or compress a whole folder by using its path.
Code to Create 7z Archive in C#
For creating an archive of type 7z C# environment details and sample code is shared here. This code takes the path of a folder and creates a 7zip archive file containing all the contents of the folder. Moreover, you can enhance this code to incorporate AES encryption and password protection for the archive. Note that you can scale this code by embedding this into a thread-based application while taking the benefit of parallel processing.
This tutorial explains the details for working with 7zip C#-based application. However, if you want to learn to extract files from a ZIP file, you can read the article on how to extract ZIP file in C#.