Introduction
RAR archives are a popular way to compress multiple files into a single package. In this article, you will learn how to unrar or extract files from a compressed RAR archive using C# .NET. We will cover various scenarios, including handling password-protected archives, and provide practical code examples to guide you through the process.
Table of Contents
- C# RAR Extractor or Opener – Free Download
- Unrar a Specific File from RAR in C#
- Extract All Files from RAR Archive in C#
- Unrar a Particular File from Password Protected RAR
- Unrar All Files from Password Protected RAR Archive in C#
- Get a Free License for the C# .NET Unrar API
C# RAR Extractor or Opener – Free Download
The Aspose.ZIP for .NET API is a robust solution that supports archiving and extracting files from various formats, including RAR (both RAR4 and RAR5), ZIP, and 7Z. You can easily install this library by downloading it from the Downloads section or by using the following command in the Package Manager Console in Microsoft Visual Studio:
PM> Install-Package Aspose.Zip
Unrar a Specific File from RAR in C#
To extract a specific file from a RAR archive, follow these steps:
- Load the input RAR file using the RarArchive class.
- Create a new file using the Create() method.
- Open the desired entry from the RAR archive.
- Write the extracted data to the newly created file.
Here’s an example code snippet demonstrating how to unrar a specific file programmatically in C#:
Extract All Files from RAR Archive in C#
To unrar or extract all files from a RAR archive, follow these steps:
- Load the input RAR file.
- Extract all files to a specified directory.
The following code illustrates how to unrar all files from a RAR archive programmatically in C#:
Unrar a Particular File from Password Protected RAR
Extracting a specific file from a password-protected RAR archive involves these steps:
- Load the encrypted RAR file.
- Specify the output file name.
- Use the Extract() method to unrar the password-protected file.
Here’s how you can achieve this in C#:
Unrar All Files from Password Protected RAR Archive in C#
To extract all files from a password-protected RAR archive, follow these steps:
- Load the encrypted RAR file.
- Unrar or extract all password-protected files from the archive.
The following code snippet demonstrates how to unrar all files from a password-protected RAR file programmatically in C#:
Get a Free License for the C# .NET Unrar API
You can evaluate the Aspose.ZIP API without any limitations by applying for a Free Temporary License. This allows you to explore the full capabilities of the library, including handling RAR archives efficiently and securely.
Conclusion
In this article, you’ve learned how to unrar or extract files from RAR archives in C#. We covered various scenarios, including extracting files from password-protected archives, providing you with a comprehensive understanding of the C# unrar library for .NET. For further exploration, you can visit the API Documentation for additional features and functionalities. If you have any questions, feel free to reach out through the Free Support Forum.