
Aspose.ZIP for .NET
C# .NET API to Compress & Decompress ZIP, RAR Files
.NET Compression API allows Software Developers to Compress and Decompress Files, Folders, Directories and Password Protect the ZIP Archives in C# Apps.
What is Aspose.ZIP for .NET?
Aspose.ZIP for .NET is a robust document compression and archive management API designed to help developers efficiently compress and decompress files and folders with minimal coding effort. This versatile library simplifies the process to create, extract, modify, and manipulate archives across a wide array of formats, including ZIP, 7Zip, RAR, TAR, GZIP, BZ2, LZ, CPIO, XZ, Z, and CAB. It offers extensive functionality for managing file structures, allowing users to compress directories, insert or delete entries in existing archives, and store files without compression, all while seamlessly integrating into ASP.NET web apps or Windows Forms across various operating systems.
To ensure data security, the library excels in creating encrypted archives, supporting industry-standard algorithms such as AES 128, AES 192, and AES 256. This makes it an ideal solution for the secure storage and transfer of sensitive data, enabling developers to password-protect specific entries or apply encryption to entire 7z archives. Furthermore, Aspose.ZIP for .NET is optimized for performance with stream support, allowing for the processing of large archives without loading the entire file into memory. By providing granular control over the encryption and decryption process, this API delivers a highly efficient and secure toolset for modern application development.
Getting Started with Aspose.ZIP for .NET
The recommend way to install Aspose.ZIP for .NET is using NuGet. Please use the following command for a smooth installation.
Install Aspose.ZIP via NuGet Command
NuGet\Install-Package Aspose.Zip You can download the library directly from Aspose.ZIP product page.
Compress & Extract Archive via .NET API
Aspose.ZIP for .NET gives software developers the capability to compress or extract archives inside their own .NET applications. The library has provided support for some commonly archive format such as ZIP, RAR, 7Zip, GZIP, BZ2 and numerous Linux format such as CPIO, TAR, Lzip, Bzip2, XZ and Z. The library has provided support for several basic and advanced features, such as ZIP files with password, extract a particular file from archive, Unzip Password Protected Zip, apply encryption and decryption, and so on.
How to Compress Multiple Files using C#?
using (FileStream zipFile = File.Open(dataDir + "CompressMultipleFiles_out.zip", FileMode.Create))
{
using (FileStream source1 = File.Open(dataDir + "alice29.txt", FileMode.Open, FileAccess.Read))
{
using (FileStream source2 = File.Open(dataDir + "asyoulik.txt", FileMode.Open, FileAccess.Read))
{
using (var archive = new Archive())
{
archive.CreateEntry("alice29.txt", source1);
archive.CreateEntry("asyoulik.txt", source2);
archive.Save(zipFile, new ArchiveSaveOptions() { Encoding = Encoding.ASCII, ArchiveComment = "There are two poems from Canterbury corpus" });
}
}
}
}
Create Password Protected Archive via C#
Aspose.ZIP for .NET enables software developers to compress and decompress files or folders with password protection inside their own C# .NET applications without worrying about the underlying file structure. The library has included several important features related to archive protection and encryption, such as encryption of files with AES192, encryption of files with AES256, password protect directory, encrypt multiple files with mixed encryption techniques, decompress AES encrypted archives, decompress AES encrypted stored archive, decompress encrypted folder to directory, decompress archive having single file, decompress archive having multiple files, extract stored archive without compression.
How to Encrypt Single File with Traditional Encryption Techniques via C#.NET API?
using (FileStream zipFile = File.Open(dataDir + "CompressWithTraditionalEncryption_out.zip", FileMode.Create))
{
using (FileStream source1 = File.Open(dataDir + "alice29.txt", FileMode.Open, FileAccess.Read))
{
var archive = new Archive(new ArchiveEntrySettings(null, new TraditionalEncryptionSettings("p@s$")));
archive.CreateEntry("alice29.txt", source1);
archive.Save(zipFile);
}
}
Create self-extracting (SFX) Archive via C#
Aspose.ZIP for .NET has provided software developers the capability for creating and managing a self-extracting (SFX) archive inside their own .NET applications. A self-extracting (SFX) archive is an executable file with an embedded archive that can be extracted automatically after launch. The library has included several important features for handling self-extracting archive such as creating a self-extracting archive instantiate, set password, running self-extracting archive (requires .NET Framework 2.0 or higher) and so on. The library also provided some command line options for self-extracting archive.
How to Compose a Self-extracting Archive via C# API?
using (FileStream zipFile = File.Open("archive.exe", FileMode.Create))
{
using (var archive = new Archive())
{
archive.CreateEntry("entry.bin", "data.bin");
var sfxOptions = new SelfExtractorOptions()
{
ExtractorTitle = "Extractor",
CloseWindowOnExtraction = true,
TitleIcon = "C:\pictorgam.ico"
};
archive.Save(zipFile, new ArchiveSaveOptions() { SelfExtractorOptions = sfxOptions });
}
}
Convert ZIP Archive to tar.gz, tar.lz, tar.xz & More via .NET API
Aspose.ZIP for .NET enables software developers to convert ZIP Archive to many other file formats with ease such as tar.gz, tar.lz, tar.xz and so on. A tar.gz file is a combination of a .tar file and a .gz file. It is considered one of the most widespread compressed archive formats in the Linux world and on the other hand ZIP is the most popular for Windows. Aspose.ZIP for .NET has provided complete support for extract entries from the ZIP archive and directly put them to the tar.gz archive with just a couple of lines of code. Below examples shows how to achieve this.
How to Extract Entries from the ZIP Archive via .NET API?
using (Archive source = new Archive("source.zip"))
{
using (TarArchive tar = new TarArchive())
{
foreach (ArchiveEntry entry in source.Entries)
{
if (!entry.IsDirectory)
{
MemoryStream mem = new MemoryStream();
entry.Open().CopyTo(mem);
tar.CreateEntry(entry.Name, mem);
}
}
tar.SaveGzipped("result.tar.gz");
}
}
