In my installer a user has a choice to download some additional files optionally... According to our statistics exactly 100% of our users get an error after WebClient is done downloading!
This is the code I use:
This is the downloading part!
If TwentyFive.Checked = True Then
Label5.Text = "Status: Downloading..."
Dim client1 As WebClient = New WebClient
AddHandler client1.DownloadProgressChanged, AddressOf client1_ProgressChanged
AddHandler client1.DownloadFileCompleted, AddressOf client1_DownloadCompleted
client1.DownloadFileAsync(New Uri("Downloadlink"), Savefiletxtbox.Text & "\25P.zip")
Else
ProgressBar1.Visible = False
Label5.Text = ""
End If
This code to track the progress:
Private Sub client1_ProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
ProgressBar1.Value = e.ProgressPercentage
Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
Dim percentage As Double = bytesIn / totalBytes * 100
ProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
End Sub
This code when the download is over:
Private Sub client1_DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
Label5.Text = "Status: Preparing..."
ProgressBar1.Value = 0
BackgroundWorker.WorkerReportsProgress = True
Dim A As String() = {DirectoryToInstall, Savefiletxtbox.Text, DeleteZips.CheckState, Hundered.CheckState, TwentyFive.CheckState}
BackgroundWorker.RunWorkerAsync(A)
TwentyFiveTimer.Start()
And finally this code to extract the .zip it just downloaded:
Dim ZipToUnpack1 As String = (Savefiletxtbox.Text & "\25P.zip")
Dim UnpackDirectoryToInstall1 As String = (Savefiletxtbox.Text & "\25P")
Using zip2 As ZipFile = ZipFile.Read(ZipToUnpack1)
Dim b As ZipEntry
For Each b In zip2
b.Extract(UnpackDirectoryToInstall1, ExtractExistingFileAction.OverwriteSilently)
Next
End Using
End If
The users get an error along the lines, saying that the file was not located by the program and couldn't be extracted!
...I looked over the code MANY times. Everything is 100% correct and I have all my directories correctly set.
In my other project I had the same exact thing - I switched to using this:
My.Computer.Network.Downloadfile("Link")
Used the SAME exact extraction method and etc.
And the program worked with no problems.
What am I doing wrong with the WebClient? I find it weird that I am receiving this error.