我是VB.NET的新手,我在谷歌搜索了很多这个但是找不到答案。
我希望程序下载一个zip文件并使用BackgroundWorker提取它。
我有下载代码但无法找到如何使用BackgroundWorker解压缩文件。
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
downloadFile("https://dl.dropboxusercontent.com/u/85542087/test.exe", "test.exe")
Status.Text = "Downloading file from W4H Servers...."
End Sub
Private Sub downloadFile(ByVal srcPath As String, ByVal destPath As String)
Dim wClient As New System.Net.WebClient()
AddHandler wClient.DownloadProgressChanged, AddressOf downloadFile_ProgressChanged
wClient.DownloadFileAsync(New System.Uri(srcPath), destPath)
Status.Text = "Downloading file from W4H Servers...."
End Sub
Private Sub downloadFile_ProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs)
Status.Text = "Downloading file from W4H Servers...."
ProgressBar1.Maximum = e.TotalBytesToReceive
ProgressBar1.Value = e.BytesReceived
Application.DoEvents()
If e.ProgressPercentage = 100 Then
'download completed
System.Threading.Thread.Sleep(2000)
Me.Close()
Form1.Close()
Process.Start("test.exe")
End If
End Sub
上面的代码将在.exe执行路径中下载我的文件并从那里运行它。所以我想在那里提取并运行它。
zip将是“test.zip”,它包含“test.exe”。
答案 0 :(得分:0)
你可以使用这个功能:
Imports System.IO
'Declare the shell object
Dim shObj As Object = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
Public Sub UnZip()
'Create directory in which you will unzip your items.
Directory.CreateDirectory(output-Folder)
'Declare the folder where the items will be extracted.
Dim output As Object = shObj.NameSpace((output-Folder))
'Declare the input zip file.
Dim input As Object = shObj.NameSpace((path-of-zip-file))
'Extract the items from the zip file.
output.CopyHere((input.Items), 4)
End Sub