vb.net下载文件并解压缩

时间:2015-03-28 15:45:25

标签: vb.net zip compression

我想在vb中下载.zip文件,并在下载达到100%时解压缩,这是我下载文件的代码:

WC.DownloadFileAsync(New Uri(http://google.zip), "C:\Documents and Settings\All Users\Documents\google.zip")
        sw.Start()

当下载达到100%时,我需要添加什么来解压缩google.zip?

1 个答案:

答案 0 :(得分:-1)

Dim saveAs as string="C:\Documents and Settings\All Users\Documents\google.zip"
            Dim theResponse As HttpWebResponse
            Dim theRequest As HttpWebRequest
            Try 'Checks if the file exist
                theRequest = WebRequest.Create(fileUrl) 'fileUrl is your zip url
                theResponse = theRequest.GetResponse
            Catch ex As Exception
            'could not be found on the server (network delay maybe)
            Exit sub 'Exit sub or function, because if not found can't be downloaded
            End Try
            Dim length As Long = theResponse.ContentLength
            Dim writeStream As New IO.FileStream(saveAs, IO.FileMode.Create)
            Dim nRead As Integer
            Do
                Dim readBytes(4095) As Byte
                Dim bytesread As Integer = theResponse.GetResponseStream.Read(readBytes, 0, 4096)
                nRead += bytesread
                If bytesread = 0 Then Exit Do
                writeStream.Write(readBytes, 0, bytesread)
            Loop
            theResponse.GetResponseStream.Close()
            writeStream.Close()
            'File downloaded 100%

解压缩文件很简单 - > https://msdn.microsoft.com/en-us/library/ms404280%28v=vs.110%29.aspx