You can read all the details at: Unrar or Extract Files Programmatically using C#
Last active
December 23, 2021 07:04
-
-
Save aspose-com-gists/449b52340d441019d848e40c12b7e39b to your computer and use it in GitHub Desktop.
Unrar Files in C# | RAR Extractor and Opener Programmatically using C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input RAR file. | |
RarArchive archive = new RarArchive("Sample.rar"); | |
// Unrar or extract all files from the archive | |
archive.ExtractToDirectory("extracted"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load an encrypted RAR file | |
RarArchive archive = new RarArchive("Data_Password.rar"); | |
// Unrar or extract password protected files from the archive | |
// Specify password as String at second argument of method | |
archive.ExtractToDirectory("PasswordExtracted" , "Aspose"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load input RAR file. | |
using (RarArchive archive = new RarArchive("Sample.rar")) | |
{ | |
// Create a file with Create() method. | |
using (var destination = File.Create("Extracted_File1.txt")) | |
{ | |
// Open an entry from the RAR archive. | |
using (var source = archive.Entries[0].Open()) | |
{ | |
byte[] buffer = new byte[1024]; | |
int bytesRead; | |
// Write extracted data to the file. | |
while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0) | |
destination.Write(buffer, 0, bytesRead); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the RAR file Encypted with Password. | |
FileInfo fi = new FileInfo("Data_Password.rar"); | |
using (RarArchive archive = new RarArchive(fi.OpenRead())) | |
{ | |
// Specify file name for the output file. | |
using (FileStream destination = File.Create("Password_Extracted_File1.txt")) | |
{ | |
// Extract the password protected file. | |
archive.Entries[0].Extract(destination, "Aspose"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment