开发者

VB: Download ZIP file from internet (and extract)

开发者 https://www.devze.com 2023-03-14 14:38 出处:网络
I need to somehow download a ZIP file from the internet using Visual Basic. Here\'s what I currently have:

I need to somehow download a ZIP file from the internet using Visual Basic. Here's what I currently have:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim NewAppData As String
    NewAppData = Environment.ExpandEnvironmentVariables("%AppData%/.minecraft.zip")
    Call DownloadFile("http://blahblahbacksheep.co.cc/.minecraft.zip", NewAppData)
End Sub

When I debug the program it gives me the following:

Function 'DownloadFile' doesn't return a value 开发者_如何学Goon all code paths. A null reference exception could occur at run time when the result is used.

What I'm looking to do is download the ZIP file and then extract it. And if possible, show label's with percentage for example:

Downloaded: 100%
Extracting: 35%....

Could anyone give me any resources or write up a bit of code to do some/all of this?

Thanks


For the unzipping part of your question: 7-Zip is a really great, open source, file archiving utility that has a nice command-line interface. Here's an example of how to call 7-Zip from VB (once it's been installed):

Set WshShell = VBA.CreateObject("WScript.Shell")
WshShell.Run "c:\Program Files\7-Zip\7z.exe " & _
    "a -tzip myarchive.zip file.dat file2.txt file3.png", 1, True

This example compresses three files into an archive, while you want to extract files from an archive... just look up the appropriate command for that in the documentation.

Note that a command window will pop up while 7-Zip is executing, and in there you'll see a % progress indicator. If you want this indicator to appear somewhere else, then with a bit of ingenuity you can probably pipe the standard output through to some other relevant location.

0

精彩评论

暂无评论...
验证码 换一张
取 消