How to Convert ZIP to ZIP 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 ZIP via C#

Convertation from ZIP to ZIP 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 ZIP

The conversion of a ZIP archive into diverse formats necessitates a systematic and meticulous approach. Typically, ZIP archives house an array of files or records, each containing valuable data. To facilitate this transformation into formats like GZ (Gzip), LZ (Lzip), Z (Unix Compress), XZ (XZ Utils), and BZ2 (Bzip2), a widely embraced strategy involves the initial consolidation of these contents into a ZIP (Zipped Archive with Gzip Compression) format.

This methodology closely aligns with established practices within Linux environments, where ZIP archives are recognized as versatile containers. Throughout the conversion process, each individual file or record within the ZIP archive is scrupulously organized within a unified ZIP archive. This ZIP archive serves as a coherent repository, diligently preserving the original file structures and associated metadata. This encapsulation into the ZIP format streamlines the subsequent application of diverse compression algorithms and formats.

The preference for ZIP as an intermediary format is rooted in its inherent simplicity and exceptional compatibility across various Unix-like operating systems. Its capability to group files together without immediate compression application makes it a pragmatic choice. Following the successful packaging into ZIP, subsequent compression operations can be applied to generate the desired output formats, encompassing GZ, LZ, Z, XZ, or BZ2.

In essence, this comprehensive process ensures the efficient transformation of the data initially housed in the ZIP archive into a spectrum of formats, providing adaptability and compatibility across various use cases.

Convert from ZIP to ZIP - C#:

    using (Archive zip = new Archive())
    {
        using (ZipArchive zip = new ZipArchive(@"archive.zip"))
        {
            for (int i = 0; i < rar.Entries.Count; i++)
            {                        
                if (!zip.Entries[i].IsDirectory)
                {
                    var ms = new MemoryStream();
                    zip.Entries[i].Extract(ms);
                    ms.Seek(0, SeekOrigin.Begin);
                    zip.CreateEntry(zip.Entries[i].Name, ms);
                }
                else
                    zip.CreateEntry(zip.Entries[i].Name + "/", Stream.Null);
            }
        }

        zip.Save("output.zip");
    }



Free App to Convert ZIP to ZIP

Check our live demos for ZIP to ZIP 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.