2015-03-28 5 views
-2

я хочу, чтобы загрузить файл .zip в VB, и распаковывать его, когда загрузка достигла 100%, вот мой код, чтобы скачать файл:vb.net Скачать файл и распаковать его

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

Что я нужно добавить для распаковки google.zip, когда загрузка достигла 100%?

ответ

-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

Смежные вопросы