Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active January 14, 2022 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/9d4019d37d8b0b33d7e992bf09ace706 to your computer and use it in GitHub Desktop.
Save aspose-com-gists/9d4019d37d8b0b33d7e992bf09ace706 to your computer and use it in GitHub Desktop.
Convert RAR Files to ZIP in C# .NET
// Create an instance of Archive class for ZIP archive
using (Archive zip = new Archive())
{
// Load the RAR archive
using (RarArchive rar = new RarArchive(@"D:\archvie.rar"))
{
// Loop through entries of RAR file
for (int i = 0; i < rar.Entries.Count; i++)
{
// Copy each entry from RAR to ZIP
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);
}
}
// Save the resultant ZIP archive
zip.Save("output.zip");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment