Click here to Skip to main content
11,790,366 members (61,843 online)
Rate this: bad
Please Sign up or sign in to vote.
Hi I have made a working FTP downloader, but I want to get file size before downloading the file. I use e.TotalBytesToReceive but it always gives me the value of -1, while e.bytesrecived works very good . (I will use these 2 values to make a progressbar). Here is my code:

Imports System.Net
Public Class Download
    WithEvents WebIllyria As New Net.WebClient 'WithEvents WebClient As New Net.WebClient

    Private Sub Download_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim Uri As New Uri("")
            WebIllyria.Credentials = New Net.NetworkCredential("username", "password")
            WebIllyria.DownloadFileAsync(Uri, "c:\illyria.exe")
        Catch ex As Exception
        End Try
    End Sub
    Private Sub WebIllyria_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles WebIllyria.DownloadProgressChanged
        ProgressDownload.Value = e.ProgressPercentage
        Label4.Text = e.TotalBytesToReceive
        Label3.Text = e.BytesReceived
        Label2.Text = e.ProgressPercentage & "%"
        If ProgressDownload.Value = 100 Then
            MessageBox.Show("Download Completed!!")
            Label2.Text = "..."
        End If
    End Sub
End Class
Posted 14-Aug-12 10:26am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Kenneth Haugland at 14-Aug-12 16:45pm
This seems like vagly familiuare thechnic :)
Wes Aday at 14-Aug-12 16:47pm
Go with what works :-)
Chriscs7 at 15-Aug-12 10:41am
Thank you but this doesn't help me at all. I tried it and I get conflict with my actual code...

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

  Print Answers RSS
0 OriginalGriff 315
1 ppolymorphe 219
2 Richard MacCutchan 158
3 Jochen Arndt 95
4 Maciej Los 90
0 OriginalGriff 1,114
1 Maciej Los 825
2 KrunalRohit 686
3 CPallini 611
4 ppolymorphe 610

Advertise | Privacy | Mobile
Web02 | 2.8.1509028.1 | Last Updated 14 Aug 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100