Question

Okay, so I have searched for dll files that will allow me to unrar files and I was able to find quite a few such as unrar.dll, chilkat, sharpcompress and some more but I wanted to use the one provided by Rar themselves.

So I referenced the DLL file in my project and imported it. I was using unrar.dll.

But I wasn't able to find any up to date code to allow me to test and try things out. All the examples I found were either not up to date or not for Vb.net.

I also tried the official example, which came in the installation but that didn't work even after I fixed it and when I tried to use the code I always got an error for

object reference not set to an instance of an object

I just want to unrar a rar file from a specific location to the root directory of my program so if my program was on the desktop I want it to unrar a file in My documents and extract the files to my desktop.

Was it helpful?

Solution

If you just want to unrar files, I Was able to do that with SharpCompress

First I created a new VB.Net App and added a reference to SharpCompress.dll before using this code to extract all the files from a Rar file.

'Imports 
Imports SharpCompress.Archives
Imports SharpCompress.Common

'Unrar code
Dim archive As IArchive = ArchiveFactory.Open("C:\file.rar")

For Each entry In archive.Entries
    If Not entry.IsDirectory Then
        Console.WriteLine(entry.Key)
        entry.WriteToDirectory("C:\unrar", New ExtractionOptions With  
                              {.ExtractFullPath = True, .Overwrite = True})
    End If
Next

More code samples

OTHER TIPS

for those who will try in vb.net the extract options are renamed and used as

Dim options As New ExtractionOptions With {
    .ExtractFullPath = True,
    .Overwrite = True
}
entry.WriteToDirectory(Application.StartupPath, options)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top