How to Convert ZIP to 7ZIP Using C#

First, you need to obtain and reference the Aspose.Zip library in your C# project. You can typically download it from the Aspose website or use a NuGet package if available. Package manager, search for Aspose.ZIP and install. You may also use the following command from the Package Manager Console.

Manage NuGet packages with the Visual Studio Package

Package Manager Console Command:

PM> Install-Package Aspose.Zip

Steps to Convert ZIP to 7ZIP via C#

Convertation from ZIP to 7ZIP consist of following steps:

  • Extract archive to intermediate storage
  • Compress extracted data to desired format

System Requirements

Before running the conversion example code, make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with .NET Framework, Mono and COM Interop.
  • Development environment like Microsoft Visual Studio.
  • Aspose.Tasks for .NET DLL referenced in your project.

Sample code to convert from ZIP to 7ZIP

Converting ZIP files to 7ZIP format using C# is a well-structured process that leverages the capabilities of the Aspose.Zip library. To initiate this conversion, you must first obtain and reference the Aspose.Zip library within your C# project. This library can be easily acquired by downloading it from the Aspose website or conveniently installed through the NuGet package manager in Visual Studio. It is imperative to ensure that your development environment, including Visual Studio, is properly set up and meets the system requirements, such as having the .NET Framework and COM Interop support in place.

The conversion itself involves two crucial stages: extraction and compression. In the initial step, the Aspose.Zip library is employed to extract the contents of the ZIP file, effectively decompressing the ZIP archive to access the original files and directories. Following the successful extraction, the library’s functionality is harnessed to compress the extracted data into the desired 7ZIP format. This process ensures that the files and directories are packaged while retaining their hierarchical structure and associated metadata. Ultimately, you save the result as a 7ZIP archive, which contains the same content as the original ZIP file. This conversion equips you with an efficient 7ZIP archive suitable for streamlined storage, transfer, and compatibility across various applications and platforms.

Code from ZIP to various formats: The ZIP archive typically contains multiple records or files. To convert this archive into formats such as GZ (Gzip), LZ (Lzip), Z (Unix Compress), XZ (XZ Utils), and BZ2 (Bzip2), a common approach is to first package the contents into a TAR (Tape Archive) format. This process is reminiscent of the typical practice in Linux environments.

In this conversion process, each file or record within the ZIP archive is first bundled together into a single TAR archive. This TAR archive serves as a container for the individual files, preserving their original structure and metadata. Once the data is encapsulated within the TAR archive, it becomes easier to apply different compression algorithms and formats.

The choice of TAR as an intermediate format is due to its simplicity and wide compatibility across various Unix-like operating systems. It provides a straightforward way to group files together without applying compression directly. After the TAR packaging is complete, subsequent compression operations can be applied to the TAR archive to generate the desired output formats, such as GZ, LZ, Z, XZ, or BZ2.

Convert from ZIP to 7ZIP - C#:

    using (SevenZipArchive sevenZipArchive =  new SevenZipArchive(new SevenZipEntrySettings(new SevenZipLZMA2CompressionSettings(1048576))))
        using (Archive archive = new Archive(""))
            for (int i = 0; i < archive.Entries.Count; i++)
                var ms = new MemoryStream();
                ms.Seek(0, SeekOrigin.Begin);
                sevenZipArchive.CreateEntry(archive.Entries[i].Name.Replace('\\', '/'), ms);


Free App to Convert ZIP to 7ZIP

Check our live demos for ZIP to 7ZIP conversion with following benefits

A reliable Aspose.ZIP Library that can compress, extract, encrypt, decrypt, convert and merge archives. Aspose.ZIP for .NET API allows to manipulate various archive types without without going into the underlying complexity of the compress file formats with minimum coding efforts.

Other Supported ZIP Conversions

You can also convert ZIP into many other file formats including few listed below.