-1

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.

4

2 回答 2

3

如果您只想解压缩文件,我可以使用SharpCompress

首先,我创建了一个新的 VB.Net 应用程序并添加了对 SharpCompress.dll 的引用,然后使用此代码从 Rar 文件中提取所有文件。

'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

更多代码示例

于 2013-08-30T02:31:44.327 回答
1

对于那些将在 vb.net 中尝试的人,提取选项被重命名并用作

Dim options As New ExtractionOptions With {
    .ExtractFullPath = True,
    .Overwrite = True
}
entry.WriteToDirectory(Application.StartupPath, options)
于 2018-05-22T09:01:20.407 回答