Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!

VB
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:
VB
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:
VB
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.
Posted
Comments
dimaba10000 28-Apr-15 11:20am    
Can anyone help :( ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900