How to Convert RAR to ZIP Using C#

In order to convert RAR to ZIP, we’ll use

Aspose.ZIP for .NET

API which is a feature-rich, powerful and easy to use archive conversion API for C# platform. Open

NuGet

package manager, search for Aspose.ZIP and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


PM> Install-Package Aspose.Zip

Steps to Convert RAR to ZIP via C#

Convertation from one archive format to another consist of following steps:

  1. Extract archive to intermediate storage
  2. 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.ZIP for .NET DLL referenced in your project.

Sample code to convert from RAR to ZIP

Convert from RAR to ZIP - C#


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

    zip.Save("output.zip");
}
  • Free App to Convert RAR to ZIP

    Check our live demos for RAR to ZIP conversion with following benefits.

      No need to download or setup anything.
      No need to write any code.
      Just upload your RAR archive and hit the "Convert" button.
      You will instantly get the download link for ZIP file.
    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 Conversions

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

    RAR TO ZIP (Zipped (compressed) Files)
    RAR TO 7ZIP (7zip Archive)
    RAR TO TAR.BZ2 (Burrows–Wheeler Compressor)
    RAR TO CPIO (Copy In, Copy Out Archive)
    RAR TO TAR.GZ (Streaming Deflate Compressor)
    RAR TO TAR.LZ (LZMA Multi-Block Compressed Data)
    RAR TO TAR (Tape Archive)
    RAR TO TAR.XZ (Container for Compressed Streams)
    RAR TO TAR.Z (LZW Compressor)