This short tutorial guides on how to turn RAR into ZIP in C#. It has all the details to set the development environment, a list of coding steps to write the application, and a runnable sample code for the transformation of RAR into ZIP in C#. You will also learn different options to filter the contents while transferring data from the RAR file to ZIP.
Steps to Convert RAR File to ZIP in C#
- Add Aspose.ZIP for .NET into your project to transform a RAR into a ZIP
- Load the source RAR file into the RarArchive object
- Create a ZIP archive
- Iterate through all the entries in the loaded RAR file
- If the entry in a loop is a Folder, create a folder in the destination ZIP archive
- If the entry is a file, copy the file contents to the destination ZIP archive
- Save the resultant ZIP file on the disk
These steps explain the process to change RAR to ZIP in C#. There are two different classes available for handling RAR and ZIP files named RarArchive and Archive respectively where the RarArchive class contains features to access all the entries in a RAR file. These entries are copied into the destination ZIP file such that the folders are generated as it is and files are copied into the respective folder in the ZIP file before saving it on the disk.
Code to Turn RAR into ZIP in C#
This code demonstrates the process to develop a RAR to ZIP converter software in C# The Entries collection contains a property IsDirectory that is used to check whether the current entry is a directory or not and then the program proceeds accordingly. You may use other properties like the compressed size, creation time, last access time, modification time, name, or un-compressed size to filter the entry to be added to the resultant ZIP file.
This article has taught us to convert WINRAR to ZIP in C#. If you want to learn the process to zip a folder, refer to the article on how to ZIP folder in C#.