# VBForums CodeBank > CodeBank - Visual Basic .NET >  Download Files From Web With Progressbar

## kleinma

Here is a sample project I did up that uses a class I wrote (WebFileDownloader)

The WebFileDownloader class provides methods for downloading a file from a URL and firing events to update progress in the GUI on a progress bar or whatever you may like. 

The standard WebClient class in the .NET framework has a method for downloading a file, but there is no indication of its progress as it downloads, which is why I wrote this up.

Known limitations:
progress is returned as a long, and a progress bar takes an integer, so in the sample I convert the long to integer, which could error in BIG downloaded files.. a better solution would be to use the filesize being downloaded and calculate a good maximum to set the progress bar to. However this is GUI related, and not related to the WebFileDownloader class itself. (Just wanted to point it out)

Also make sure the URL is a full URL (ie http://www.mysite.com/file.zip and not www.mysite.com/file.zip)

Please post any corrections you may find. I use this code all the time, but that doesn't mean there isn't a bug or 2 lurking somewhere  :Wink:

----------


## RingOfFire

Thank you for the sample project.

I have a question: When the user clicks the close button (or exits application) during a download, download procedure keeps going on. 

I'd like to know how to add the following feature:

When the application is stopped somehow 
(by user, by system or other failure)

1. Stop the download process
2. Delete the file that was downloaded partially

----------


## dannyf

I noticed the buttons and progress bar in this project have the "XP" look.

How did you do that?

I can't find an option anywhere in Visual Studio?

Edit: looking through the zip file I can't find any use of manifest files or anything either?

----------


## kleinma

I enable visual styles in the Sub Main routine.

This code here

VB Code:
'SUB MAIN WHERE WE ENABLE VISUAL STYLES, AND RUN MAIN FORM
    Public Shared Sub Main()
        Application.EnableVisualStyles()
        Application.DoEvents()
        Application.Run(New frmMain)
        Application.Exit()
    End Sub


It also requires you set the buttons flatstyle property to system instead of standard. (any control that has a flatstyle property should be set to system to render it in XP theme).

.NET 2005 supports XP theme right from the get go, without needing to call this.

----------


## shery

how can i add download time estimation to this code ? i'm a beginner please help me  :Smilie:

----------


## cpatzer

Kleinma,

Thanks again, I remember you helping me with this problem on an earlier date. I do have a quesition though, of course. How does this handle proxy servers or does it? If not how should I go about implementing that functionality?

Thanks,

Christian

----------


## kleinma

It currently doesn't and I don't have a proxy server to test any code against.

However I would imagine it would probably be as simple as setting the proxy property of the WebRequest object in the DownloadFileWithProgress routine.

After the line

wRemote = WebRequest.Create(URL)

try adding

wRemote.Proxy = new WebProxy()

but specify the needed information in one of the WebProxy overloaded constructors.

That should be all there is to it.

Let me know how you make out.

----------


## cpatzer

Will do thanks.

----------


## bluehairman

Hi, I tried adding this to program to auto update and noticed that WebFileDownloader doesn't seem to work. I use VS 2005 and it says:


```
'Type 'WebFileDownloader' is not defined'
```

----------


## kleinma

did you actually add the WebFileDownloader.vb class file to your project?

----------


## bluehairman

O.O No I didn't. I never thought of that. Sorry, I'm new to .NET and don't understand some things yet.

----------


## kleinma

No problem, but that is what you need to do. Once you add that class file to your project, you can access that class.  :Wink:

----------


## jsloan2

> Thank you for the sample project.
> 
> I have a question: When the user clicks the close button (or exits application) during a download, download procedure keeps going on. 
> 
> I'd like to know how to add the following feature:
> 
> When the application is stopped somehow 
> (by user, by system or other failure)
> 
> ...


Excellent class, I just used it for a small updater program, however i did notice one thing, the downloader does not stop when the form is closed. The application remains present in the taskmanager until the download completes.

I was wondering is anyone had any insight on how to make the downloader stop. I've never really used any web/http classes before they aren't really my forte. Maybe some kind of cancel event or something could be raised? I'm not really sure where this would be coded though. And i guess we'd have to clean up the partial stream. I'm kinda tired right now as I'm posting this so my brains not working 100%.

Maybe just adding a cancel event  that changes a member variable blnCancel = True and modifying some of the loops to check that variable will work. Then raising the event when the form closes would work, might not be the cleanest but I'll try it after I wake up. If it works I'll repost modified code if that's ok.

Another thing I noticed is that download speed seem to dramatically increase after the downloaded stream starts reporting its size in MB rather than KB on my cable modem. I would say on average of 3-5x the speed it takes to go from 0 to 1MB. Not sure why this might be.

Anyway again, thanks for the class, saved me some time!

----------


## kleinma

well generally you would not want to allow the form to be closed while downloading. However if you want to offer a cancel option, you could simply set a boolean variable in the downloader class to indicate you want to cancel the download. Then in the DownloadFileWithProgress routine, check this boolean value in the do loop, and drop out of it if infact the cancel var is set to true. You may also want to delete the semi downloaded file when this happens, and maybe even add a new event like "DownloadCancelled". I did try to add a pause feature in recently, but so far it is still a little buggy.

Also I am not sure about what you say regarding the download speeds when the file is over 1MB downloaded. I don't notice any significant speed changes between 0-1 MB and then larger... How big are the files you are downloading?

----------


## sdk1985

> well generally you would not want to allow the form to be closed while downloading. However if you want to offer a cancel option, you could simply set a boolean variable in the downloader class to indicate you want to cancel the download. Then in the DownloadFileWithProgress routine, check this boolean value in the do loop, and drop out of it if infact the cancel var is set to true. You may also want to delete the semi downloaded file when this happens, and maybe even add a new event like "DownloadCancelled". I did try to add a pause feature in recently, but so far it is still a little buggy.
> 
> Also I am not sure about what you say regarding the download speeds when the file is over 1MB downloaded. I don't notice any significant speed changes between 0-1 MB and then larger... How big are the files you are downloading?


I am also noticing this, just reported it in another topic. It goes from 60 kbps to 700 kbps after it switches to MB. Maybe there is a way to keep it at MB from the beginning? (file=3mb).

----------


## kleinma

are you sure it isn't just that it appears to be slower?

Remember the progress will look a lot faster when its just showing kilobytes downloaded versus megabytes...

The reason I say this, is because when progress of the download gets reported, its only in bytes, not in KB or MB.

The number of bytes is passed to the shared FormatFileSize method, which returns the correct display string (ie kb, mb, etc..)

so why don't you try NOT using the FormatFileSize, and see if you notice slowdown, I sure don't.

If you are using my exact sample project, in the *_Downloader.AmountDownloadedChanged* event, comment the line



```
lblProgress.Text = WebFileDownloader.FormatFileSize(iNewProgress) & " of " & WebFileDownloader.FormatFileSize(ProgBar.Maximum) & " downloaded"
```

and add the line



```
lblProgress.Text = iNewProgress.ToString & " of " & ProgBar.Maximum.ToString & " downloaded"
```

this will make the label only report the bytes download, and not format them into MB, KB, etc.. for display purposes. Again I think you are just thinking it looks faster before it has DLed a MB of the file.

----------


## sdk1985

Yes I am sure because I use an external program to measure download speeds (DU meter 3.07). Thats how I noticed the increase from 60 KB/s to 700 KB/s.

I'll try the code, do I need to replace the first line you gave?

Also there are some ! according to VB with the default project. (I am now using an exact copy of webfiledownloader.vb in my program)

Warning	1	Variable 'FS' is used before it has been assigned a value. A null reference exception could result at runtime.	I:\Documents and Settings\Sebas\Mijn documenten\Visual Studio 2005\Projects\FileTransfer\FileTransfer\WebFileDownloader.vb	70	21	FileTransfer

Warning	2	Function 'FormatFileSize' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	I:\Documents and Settings\Sebas\Mijn documenten\Visual Studio 2005\Projects\FileTransfer\FileTransfer\WebFileDownloader.vb	99	5	FileTransfer

----------


## sdk1985

Ok I replaced the line, now it's slow all the way. I think updating for every byte might be a little to much for the app. Now I reached 61-117 KBps, my maximum speed (of the same file) is 1058 KB/s. Do you know the line to format in MB instead of autoformat?
edit: when I remove the line entirely I get speeds from 640 - 890. Then the problem is solved... so the byte reporting is causing it to slow down.

edit2: 

This also works (1 MB/s):


```
lblProgress.Text = "Bestandsgrootte: " & WebFileDownloader.FormatFileSize(Progbar.Maximum)
```

----------


## kleinma

well that is very common no matter what...

any UI updating ALWAYS slows an app down...

if you run a tight loop that scanned every file on your computer, it would run a bunch faster than if the same loop was also updating a label with the current file it was scanning.

If you still want to show UI progress, but speed it up, you could use some sort of if statement to determine if you should update the GUI with progress or not. Since the default is to update after even chunk of the download is completed, perhaps only have it update 1 out of every 4 times the event fires or something.

----------


## sdk1985

> well that is very common no matter what...
> 
> any UI updating ALWAYS slows an app down...
> 
> if you run a tight loop that scanned every file on your computer, it would run a bunch faster than if the same loop was also updating a label with the current file it was scanning.
> 
> If you still want to show UI progress, but speed it up, you could use some sort of if statement to determine if you should update the GUI with progress or not. Since the default is to update after even chunk of the download is completed, perhaps only have it update 1 out of every 4 times the event fires or something.


Ok but it is still weird that if it switches from bytes/kb to MB then after that it's fine... Maybe because the mb figures have to change less often?

I'm new to vb 2005, thought the format was included in vb 2005. I see that you created it yourself.
So I started editing, just doing this:


```
Else
                Select Case Size / KB
                    'Case Is < 1000
                    '    Return (Size / KB).ToString("N") & "KB"
                    Case Is < 1000000
                        Return (Size / MB).ToString("N") & "MB"
                    Case Is < 10000000
                        Return (Size / MB / KB).ToString("N") & "GB"
                End Select
```

Solves the slowdown for me :Smilie: . (I commented the kb case).

----------


## RingOfFire

> well generally you would not want to allow the form to be closed while downloading. However if you want to offer a cancel option, you could simply set a boolean variable in the downloader class to indicate you want to cancel the download. Then in the DownloadFileWithProgress routine, check this boolean value in the do loop, and drop out of it if infact the cancel var is set to true. You may also want to delete the semi downloaded file when this happens, and maybe even add a new event like "DownloadCancelled". I did try to add a pause feature in recently, but so far it is still a little buggy.
> 
> (...)


As I'm a new coder: can you help me a bit more to include this code to my project? Maybe you can give some more clues, so that I can learn at the same time.

Steps (according to what you've mentioned):
1. Setting a boolean class for cancelling download
2. Include this class within the DownloadFileWithProgress routine (inside do loop)
3. Add DownloadCancelled event for erasing partially downloaded file or other stuff on "post partial-download event".

Thanks a lot!

----------


## Zoroxeus

Hi Kleinma, 
thanks for the great code,
I tried to adapt it to my case however I ran into an issue. 
My links are asp type of links and they open a doc file in MS Word.
So they have the "?" charachter in the URL. 
When I enter them on the app it's telling me that there are illegal charchters.
Any idea how this can be fixed ? 
thanks

----------


## sameer spitfire

I need to download the file from the site which ask for userid and password

i use the following code to download the file( Without userid and password)



```
Dim wClient As New System.Net.WebClient
        Dim add As String = "http://203.199.49.90/XMLXX/CCnn/15KT/Pnn_001.zip"
        Try

download:
            wClient.DownloadFile(add, "n:\genbas\Pnn_011.zip")
```

But how i can pass the userid and passwords To the above string
Plase help

----------


## cpatzer

A simple way would be this:

http://203.199.49.90/XMLXX/CCnn/15KT...serid=sam&pwd=[encrypted password here]

----------


## kleinma

> I need to download the file from the site which ask for userid and password
> 
> i use the following code to download the file( Without userid and password)
> 
> 
> 
> ```
> Dim wClient As New System.Net.WebClient
>         Dim add As String = "http://203.199.49.90/XMLXX/CCnn/15KT/Pnn_001.zip"
> ...


Specify the user id/password in the credentials property of the webclient before making the download call.



```
        Dim wClient As New System.Net.WebClient
        Dim add As String = "http://203.199.49.90/XMLXX/CCnn/15KT/Pnn_001.zip"
        Try
            wClient.Credentials = New Net.NetworkCredential("userid", "password")
            wClient.DownloadFile(add, "n:\genbas\Pnn_011.zip")
```

----------


## xSmurf

Nice job but how can i make it auto-update when start and how can I let it automaticly extract the rar

----------


## kleinma

Those questions are beyond the scope of what this example does. This example code is specifically just for downloading files with progress. 

You should really ask your questions in the main VB.NET forum.

----------


## xSmurf

deleted

----------


## michalss

Nice sample but how can i add authentical for rapidshare.com. Thx

----------


## kleinma

> Nice sample but how can i add authentical for rapidshare.com. Thx


In the downloader class, in the routine called DownloadFileWithProgress you could add the following line of code:


```
wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
```

this should go right after


```
wRemote = WebRequest.Create(URL)
```

and before


```
Dim myWebResponse As WebResponse = wRemote.GetResponse
```

----------


## michalss

> In the downloader class, in the routine called DownloadFileWithProgress you could add the following line of code:
> 
> 
> ```
> wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
> ```
> 
> this should go right after
> 
> ...



Im sorry for my question but can you give me more info or simple exaple appl. Thx i will be more then greatfull...

EDIT : I Have Try your exaple and i was add this syntaxe but it did not work...

----------


## kleinma

what more do you need? 

1) download and open up the my example code
2) go into the class file called WebFileDownloader
3) find the routine called DownloadFileWithProgress 
4) find the line of code mentioned above
  wRemote = WebRequest.Create(URL)
5) insert this code after it
  wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
6) change USERNAME and PASSWORD to actual valid values
7) test code against site that needs authentication

----------


## michalss

> what more do you need? 
> 
> 1) download and open up the my example code
> 2) go into the class file called WebFileDownloader
> 3) find the routine called DownloadFileWithProgress 
> 4) find the line of code mentioned above
>   wRemote = WebRequest.Create(URL)
> 5) insert this code after it
>   wRemote.Credentials = New Net.NetworkCredential("USERNAME", "PASSWORD")
> ...



Its not working i have try it just now



```
  FS = New FileStream(Location, FileMode.Create, FileAccess.Write)
            wRemote = WebRequest.Create(URL)
            wRemote.Credentials = New Net.NetworkCredential("myname", "mypass")
            Dim myWebResponse As WebResponse = wRemote.GetResponse
            RaiseEvent FileDownloadSizeObtained(myWebResponse.ContentLength)
            Dim sChunks As Stream = myWebResponse.GetResponseStream
            Do
                iBytesRead = sChunks.Read(bBuffer, 0, 256)
                FS.Write(bBuffer, 0, iBytesRead)
                iTotalBytesRead += iBytesRead
                If myWebResponse.ContentLength < iTotalBytesRead Then
                    RaiseEvent AmountDownloadedChanged(myWebResponse.ContentLength)
                Else
```

Can you check it for me pls?

EDIT : Its download only 5 Kb from 100 MB....

----------


## kleinma

they might be doing some sort of redirect on the server, so you may only be getting the first response.

I dont know how rapidshare servers work and if they just serve out the file when you navigate to it, or do some sort of redirect. Chances are if you are getting 5KB, its HTML.

----------


## michalss

> they might be doing some sort of redirect on the server, so you may only be getting the first response.
> 
> I dont know how rapidshare servers work and if they just serve out the file when you navigate to it, or do some sort of redirect. Chances are if you are getting 5KB, its HTML.


Thx for quick response : I have try download http://rs201.rapidshare.com/files/82...9.0.0e-DVT.rar

How ever is any chance to get close have a look on this problem pls? Im really desperate to get it work. Im looking for solution almoust 2 months. I can also pay for your time if is it reuquire.... Thx

----------


## kleinma

do you have a premium acct for rapidshare?

----------


## michalss

> do you have a premium acct for rapidshare?



Yes i have 2 if you need ...

----------


## kleinma

well just by looking at the site, they defenitly do some funky redirects (at least when u use the free downloading service). They might even do direct response writing of the files to prevent people from direct linking.

If you want to PM me one of your acct id/passwords, I will test trying to make it work, as it may be easier when you have an actual paid acct to work with. I can't promise I will be able to get back to you right away, but if you PM me with that info, I will look at it when I have a few free minutes.

----------


## mjcm

Here is a link to an article from Karl Moore, that can determine if a connection to the internet is available.

http://www.developerfusion.co.uk/show/3903/

----------


## kleinma

That code from Karl will actually error.. it should be written like this:



```
    Public Function IsConnectionAvailable() As Boolean
        ' Returns True if connection is available 
        ' Replace www.yoursite.com with a site that
        ' is guaranteed to be online - perhaps your 
        ' corporate site, or microsoft.com
        Dim objUrl As New System.Uri("http://www.yoursite.com/")
        ' Setup WebRequest
        Dim objWebReq As System.Net.WebRequest = Nothing
        objWebReq = System.Net.WebRequest.Create(objUrl)
        Dim objResp As System.Net.WebResponse = Nothing
        Try
            ' Attempt to get response and return True
            objResp = objWebReq.GetResponse
            objResp.Close()
            objWebReq = Nothing
            Return True
        Catch ex As Exception
            ' Error, exit and return False
            If objResp IsNot Nothing Then
                objResp.Close()
                objWebReq = Nothing
                Return False
            End If
        End Try
    End Function
```

----------


## S-One

hello people, this is my first post...
First, best regards for kleinma, this is what i need for my project for school,
i know that old thread but must try...

i need to figure the whole core so i can adjust it and put in my project...
here is a question:
why i need this ??? it is a property ok, but in whe class it only use first line mCurrentFille, i didnt see the roll of property... i have remove it and it still works..... so why ?  :Smilie: ))


```
Private mCurrentFile As String = String.Empty

    Public ReadOnly Property CurrentFile() As String
        Get
            Return mCurrentFile
        End Get
    End Property
```

back to work... more questions to come  :Smilie: ))
i need to figure it out how to fix bug with "after close it still downloads"
also for my project i need to download list of url's......... my app generates web urls and i need to download it all..... i need to figure it out how... maybe some loop...

great work !!!

----------


## kleinma

It is really just a helper property incase you want to access the name of the file being downloaded by the downloader class, from the code that calls the download.

So in the example app, there is code in the form that handles the _Downloader.FileDownloadComplete event.

It looks like this:


```
    'FIRES WHEN DOWNLOAD IS COMPLETE
    Private Sub _Downloader_FileDownloadComplete() Handles _Downloader.FileDownloadComplete
        ProgBar.Value = ProgBar.Maximum
        MessageBox.Show("File Download Complete")
    End Sub
```

However you could do something like this using that property:


```
    'FIRES WHEN DOWNLOAD IS COMPLETE
    Private Sub _Downloader_FileDownloadComplete() Handles _Downloader.FileDownloadComplete
        ProgBar.Value = ProgBar.Maximum
        MessageBox.Show("File Download for " & _Downloader.CurrentFile & " Complete")
    End Sub
```

Another option would be making a custom eventargs to pass to that event that includes the filename of the downloaded file instead, I just didn't make it that robust because I did not have a need to for the app I coded this for originally.

----------


## S-One

True True, thx for fast reply...
i have put some check for URL that user type in...
if user put http:// or if not, app will put...
before that app report error... and user must type WHOLE url... and we know how users are  :Smilie: )))))))))



```
in
    Private Sub cmdDownload_Click
        If Mid(txtURL.Text, 1, 7) <> "http://" Then
            Dim temp, http As String
            temp = txtURL.Text
            http = "http://"
            txtURL.Text = http & temp
        End If
------------- continue core
        'Download
        Try
            _Downloader = New WebFileDownloader
            _Downloader.DownloadFileWithProgress(txtURL.Text, txtDownloadTo.Text.TrimEnd("\"c) & GetFileNameFromURL(txtURL.Text))
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message)
        End Try
    End Sub
```

but i have one problem:
i have form1, and on form1 i have button, when click form2 pop up...
but if i close form1 form2 also will be closed... how can i make form2 stay?
AND what is key word for checking IS FORM2 ACTIVE ? of IS FORM2 opened?

thx
SxOne

----------


## kleinma

What version of Visual Studio are you using?

In 2005 and above, there is a setting in project properties which says "Shutdown Mode" and it is set to "When Startup Form Closes" by default.

So if Form1 is your startup form, then closing it tells you app the whole thing should close. Change this value to "when last form closes" and that should solve your issue.

Form.ActiveForm will return the active form anywhere inside your application. It is a shared property so no instance is required to use it. It can however return a value of Nothing, in the event there is no active form.

----------


## S-One

hehe i see what shutdown option in 2005 studio, but for this project i write in 2003  :Frown: (((((((((( shame, i have converted to 2005 but design of app. is not like it need to be  :Frown: 


```
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterAllFormsClose
```

ok for now i will use form2.showDialog() so thats ok for now  :Smilie: 
thx for Form.ActiveForm but i think that i cant check if form2 is open, because if i try to close form1 and in "closing" event of form1 i put Form.ActiveForm Form1 will be active  :Smilie:  so must be something else..  but not important i will escape from that...

thx Kleinma  :Wink:

----------


## S-One

hey do you have some idea how can i download more then one file from web... some loop
actually let me explain...

i have app that generates list of url's



```
http://www.vbforums.com/file01.zip
http://www.vbforums.com/file02.zip
.....
http://www.vbforums.com/file20.zip
```

after that a need to download it all....
i have an idea that maybe its best to put them in .txt file and forward it to your Download app.....

i need to figure it how...
out to work on it  :Smilie:

----------


## kleinma

I guess it depends on if you want to download one file at a time, or all of them at once. It was not really designed to perform multiple async downloads at the same time, however if you are just talking about downloading multiple files, one after another, then it could be as simple as making a list of files to download, and in the download complete event that fires off when a download has completed, you simply kick off the call to download the next file, until all files have been downloaded.

----------


## S-One

yes, i mean one file at a time, not multiple...
thanks for idea, i will try that !!!

----------


## S-One

> Also there are some ! according to VB with the default project. (I am now using an exact copy of webfiledownloader.vb in my program)
> 
> Warning	1	Variable 'FS' is used before it has been assigned a value. A null reference exception could result at runtime.	I:\Documents and Settings\Sebas\Mijn documenten\Visual Studio 2005\Projects\FileTransfer\FileTransfer\WebFileDownloader.vb	70	21	FileTransfer
> 
> Warning	2	Function 'FormatFileSize' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.	I:\Documents and Settings\Sebas\Mijn documenten\Visual Studio 2005\Projects\FileTransfer\FileTransfer\WebFileDownloader.vb	99	5	FileTransfer


Hmm, i have converter my project from .net 2003 to 2005 and i also get this Warning, weird, but there is return  :Confused:  

also i get warning abour DialogResult.no, yes, or whatever is used...
i have resolved this with


```
System.Windows.Forms.DialogResult....
```

EDIT:
ok i have resolved *FormatFileSize* Warning *Case else* is missing:


```
                Select Case Size / KB
                    Case Is < 1000
                        Return (Size / KB).ToString("N") & "KB"
                    Case Is < 1000000
                        Return (Size / MB).ToString("N") & "MB"
                    Case Is < 10000000
                        Return (Size / MB / KB).ToString("N") & "GB"
                    Case Else
                        Return Size.ToString & "bytes"
                End Select
```

Matt can you explain this please ("D" & "N" is format right):
Size.ToString("D")    .ToString("N")
also cant find help about URL.IndexOf("/"c) and URL.LastIndexOf("/"c)
what is c for ? (description is Char, but please explain  :Smilie: 

thx in advance !

----------


## kleinma

> Hmm, i have converter my project from .net 2003 to 2005 and i also get this Warning, weird, but there is return  
> 
> also i get warning abour DialogResult.no, yes, or whatever is used...
> i have resolved this with
> 
> 
> ```
> System.Windows.Forms.DialogResult....
> ```
> ...


Yeah this project was originally done in VS2003 (.NET 1.1) they added in some warnings in the newer versions of VS, so that is what you were seeing.

Those fixes you made were fine.

"D" is for decimal formatting of a number as a string, and "N" is for general number formatting of a number as a string. In some cases, they may yield the same result, and in others they will not. (usually has to do with number of decimal place precision, etc..)

Here is a listing of valid numeric formats for calling ToString
http://msdn.microsoft.com/en-us/libr...9k(VS.80).aspx

The IndexOf method is a method that simply returns the numeric index of where a given character is in a string of characters.

So given the string "abccba", the character positions of the letters are as follows: 

a = 0
b = 1
c = 2
c = 3
b = 4
a = 5

So if I were to get the indexof("a"c), it will return 0, as a is found at position 0 in this string, however getting lastindexof("a") does the same thing, but starts at the end of the string, in which case it will find a in position 5, so it will return a 5.

the c after the specified character is just to tell the compiler "this is a datatype char, not a string with only 1 character". By default VB thinks anything in quotes is a string.

----------


## S-One

thanks Matt !!!
great answer !!!

----------


## S-One

Hey Matt, can i ask for one more thing, can you help me how to delete file that didnt whole downloaded, i made Cancel button but cant figure it out where to put delete method, and which is a delete method...

is this enough to Flush all buffers from memory or need something more ?


```
                If Cancel = True Then
                    sChunks.Close()
                    FS.Close()
                    FS = Nothing
                    RaiseEvent CancelResetLabelText()
                    Return False
                End If
```

this is in "DownloadFileWithProgress" Do While Loop
i need this for school project so if you can please help me...

----------


## S-One

i have resolved problem with deleting non downloaded file.

In "DownloadFileWithProgress" function in Do While Loop, i have added Cancel option before and in that part i have added this line:
*My.Computer.FileSystem.DeleteFile(Location.ToString)*

[code]
            Do
                If Cancel = True Then
                    sChunks.Close()
                    FS.Close()
                    FS = Nothing
*                    My.Computer.FileSystem.DeleteFile(Location.ToString)*
                    RaiseEvent CancelResetLabelText()
                    Return False
                End If
.................
[code]

it works great file is deleted if it's canceled, so now my project is finished... i will post Screenshots later...
thanks again matt for Help, and fot this application !!!!!!!!!!!
Best Regards,
ShOne from Serbia

----------


## adzie

superb script.

Quick question, is it possible to modify to download a web folders contents as opposed to a file???

cheers  :Smilie:

----------


## kleinma

it downloads the file over HTTP, so if you knew the specific file names, then of course you could run it in a loop and download each file.

If you mean can you point it to a folder location on the web, and have it download every file without knowing their names, then no. A webserver doesn't serve up the list of files in a given folder unless directory browsing is on. If directory browsing was on, you could in theory navigate to the directory, parse the list of files, and then download them individually because you would now have their names.

If you were to go a different route, like FTP if it were possible for you, then you can do things like list the contents of a directory without downloading anything, and then download the entire directories contents.

----------


## adzie

wow that was quick  :EEK!:  

I have director browsing installed and I only want to use it for small files but many of them.

I'm new so please be gently  :Big Grin:  

What do I need to do to get the directory downloaded

again many thanks  :Smilie:

----------


## kleinma

you would want to download the HTML that is output by your webserver when you visit that page, and parse it to get the file names. Once you have each individual file name in a collection or an array, then you could use my code in this thread to loop and download each file.

You should really start a new thread in the VB.NET section of this forum, asking about downloading and parsing a file list from a website with directory browsing on.

----------


## adzie

Matt,

Will do thanks for directing me in the right direction.

Your script is a real diamond

----------


## kleinma

Check back soon, I am working on a new version which has a few extra features.

----------


## S-One

Hey Matt, me again
Can you explain to me why did you wrote this line ?
Dim myWebResponse As WebResponse *= myWebRequest.GetResponse*

i understand first part, but why did you initializes it ?? and what did you get with it ?
also this line same question
Dim myStream As Stream *= myWebResponse.GetResponseStream*

thx in advance...
Sxone

----------


## kleinma

You don't get a response from your request to download a file until you call the GetResponse method. When you do that, the response is returned from the class as a WebResponse object.

So that line of code
Dim myWebResponse As WebResponse = wRemote.GetResponse

is saying

Declare myWebResponse as a WebResponse object and set it to the response from the WebRequest called myWebRequest.

So once you create your webrequest to download the file, you need to check the response. That is how the stateless nature of the web works, through requests from you and responses from web servers.

----------


## S-One

Niiice  :Wink: 
thanks very much...
if there is something i can do for you, like Upload something, ANYTHING, just say, you have helped me a lot with your example and code support  :Smilie: 
i have use some of your code in my project (like i sad before) for school, it is over, but i need to write report, so i'm learning how does it works...

maybe i will ask you something more, if i need :P
thanks a lot again
SxOne

----------


## kleinma

I just post on here to help out so others can learn how to program too. I love VB so I always like to help out those who are learning it.

----------


## VB6Learner

Ya the code works but there is one problem first of all it takes about five seconds before the message shows saying "Connection Found!" Second of all it freezes after the message comes up it wont allow any buttons to be clicked! I am using Microsoft Visual Basic 2008 Windows XP SP2

----------


## TetovaBoy

hia sorry mate for User login section i didn't get erectly..

can u assist me how can i make users that download files from Rapidshare or megaupload or mxupload to be able to log with their premium account..

----------


## kleinma

you should open a new thread in the VB.NET section on that. Questions here should only pertain to the specific code in the codebank submission.

----------


## TetovaBoy

is your download manager you had made just want to add User login to that download manager thets all...

----------


## kleinma

those file services require HTTP form based logins, so your actual question really should be how to perform that authentication prior to using my download code.

That is what belongs in its own thread. This web file downloader example code I have posted here is for non password protected file downloads.

----------


## NarenG

Hi, It's really a gem of Code. I need some help. How to show the estimated time, elapsed time, time remaining, etc when the file is downloading?

----------


## NarenG

I have a situation where i have two buttons and on clicking button1 i can download abc.rar and on clicking button2 i can download xyz.rar. I used your webfiledownloader class. Now my problem is that before the abc.rar is downloaded completely i clicked on button2 which will start downloading xyz.rar by stopping abc.rar. How to make xyz.rar to wait till abc.rar is finished?

----------


## NarenG

How to show estimated time, remaining time, download speed, etc when the file is downloading in this WebFileDownloader class?

----------


## Link

ehm...

I get this error in the DownloadFileWithProgress function;


vb.net Code:
FS = New FileStream(Location, FileMode.Create, FileAccess.Write)
 "Access to the path 'C:\' was denied"

Im running win xp, and there's only one user and it got full admin rights...

----------


## kleinma

what is the actual value of the "Location" variable when that occurs?

Also, can the user manually create a file on the root of C?

----------


## NarenG

How to show estimated time, remaining time, download speed, etc when the file is downloading in this WebFileDownloader class?

----------


## kleinma

you would need to calculate all those things on your own. You should develop each forumla first, like time remaining is an estimate based on the amount currently downloaded, the total file size, and the download speed.

I haven't worked these types of features into this code, but feel free to work it in, and post back with your results.

----------


## youngbucks

Kleinma could you help me to get this to report progress please? It uses .NetWebrequest as in your class.
Also is there any downfalls to using this?


vb.net Code:
Public Class Form1    Private Const filenames As String = "c:\Users\Home\Desktop\list_of_files.txt"    Private Const url As String = "http://www.fileden.com/files/2008/12/22/2233952"    Private Const savepath As String = "c:\Users\Home\Desktop\"    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        Try            Dim sr As New IO.StreamReader(filenames)            Dim line As String = sr.ReadLine()            Dim req As Net.WebRequest            Dim resp As IO.Stream            Dim out As IO.BinaryWriter            Do While line IsNot Nothing                req = Net.HttpWebRequest.Create(url & line)                resp = req.GetResponse().GetResponseStream()                out = New IO.BinaryWriter(New IO.FileStream(savepath & line, IO.FileMode.OpenOrCreate))                Dim buf(4096) As Byte                Dim k As Int32 = resp.Read(buf, 0, 4096)                Do While k > 0                    out.Write(buf, 0, k)                    k = resp.Read(buf, 0, 4096)                Loop                resp.Close()                out.Close()                line = sr.ReadLine()            Loop        Catch i As Exception            MsgBox(i.ToString)        End Try    End SubEnd Class

----------


## Link

> what is the actual value of the "Location" variable when that occurs?
> 
> Also, can the user manually create a file on the root of C?


Sorry for being so late, i totally forgot this. I have gotten a new hd lately (christmas), and it still says the same thing.

i changed the path to "C:\Documents and Settings\Steffenn\Skrivebord", still gets access denied.

also tried C:\, same.

----------


## dkittell

Thank you for posting this example. I've been looking for ways to download large files with a look like you created.

So far I've tested this to handle up to 480 MB with no problems

----------


## NarenG

Thanks for your advice. I will try it on my own.





> you would need to calculate all those things on your own. You should develop each forumla first, like time remaining is an estimate based on the amount currently downloaded, the total file size, and the download speed.
> 
> I haven't worked these types of features into this code, but feel free to work it in, and post back with your results.

----------


## coerce

hey, i am having some problems making the cancel button. I used the code provided by s-one:


```
Do
If Cancel = True Then
sChunks.Close()
FS.Close()
FS = Nothing
My.Computer.FileSystem.DeleteFile(Location.ToString)
RaiseEvent CancelResetLabelText()
Return False
End If
```

how would i call this with a button? what do you need to declare in the frmmain.vb and webfiledownloader.vb? thanks...

----------


## -Negative-

there is a way i can retrive the download speed?

----------


## Antonidas

Hello kleinma

I've downloaded your code and modified a bit in order to learn something new. I am really new to VB.NET. Now i've constated, that if I delete some parts of the code to let the downloader start automatically, an error occurs and says, that the access to the path was denied.

How is this possible? I am admin on my computer...

The codes i have deleted are, where you have to choose the path, the file URL and the download button. instead of theese functions i have defined some constants: 1) FileURL, 2)DownloadPath. The rest should start automatically, when the program is loaded.

Could you point me in the right direction?

Thank you in advance.

----------


## kleinma

what are the values of what you hard coded? The error is pretty clear that you are trying to use some path that you don't have access to.

----------


## Antonidas

i have used "Application.StartupPath()" as download path.

----------


## kleinma

I could see that happening on a Vista machine. Is that what you are using?

----------


## Antonidas

no i'm using XP media center 2005. But I have tested the program also on windows 2000 Pro... no way, access denied.

*EDIT:*
If it helps, I can post the script as i have changed it...

----------


## kleinma

I will take a look if you post it.

----------


## Antonidas

OKI, here you are.

Thank you very much!  :Smilie:   :Thumb:

----------


## kleinma

I'm guessing you did change some values in here before you uploaded it to protect some info right?

----------


## kleinma

The issue with your code is you are not specifying a full file name to download the file to. You are specifying a full URL, but only a directory to download to. You need to specify a directory AND filename to save the downloaded file as.

The access denied error is a bit cryptic, but that is what it means. The code is trying to open a file to write the downloaded data to, but you basically tell it to try to write the data to the folder itself, not a file in the folder.

Just use path.combine to fix this:



```
    Private Sub updater_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            _Downloader = New WebFileDownloader

            'GET FULL FILE PATH/NAME FROM EXE PATH AND FROM URL FILE NAME
            Dim DownloadedFileName As String = IO.Path.Combine(Application.StartupPath(), IO.Path.GetFileName(launcher))

            _Downloader.DownloadFileWithProgress(launcher, DownloadedFileName)
        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message)
        End Try
    End Sub
```

----------


## Antonidas

> I'm guessing you did change some values in here before you uploaded it to protect some info right?


yeah I only have changed the link, because it is a file, i don't want that everybody reads...




> The issue with your code is you are not specifying a full file name to download the file to. You are specifying a full URL, but only a directory to download to. You need to specify a directory AND filename to save the downloaded file as.
> 
> The access denied error is a bit cryptic, but that is what it means. The code is trying to open a file to write the downloaded data to, but you basically tell it to try to write the data to the folder itself, not a file in the folder.
> 
> Just use path.combine to fix this:
> 
> 
> 
> ```
> ...


wooow yeah... you are right! OMG it's logic... how stupid i am. thank you very very much.  :Thumb:  :Thumb:

----------


## ph4nt0m

> there is a way i can retrieve the download speed?


Thank you so much for this submission, it's helped me immensely 

I too am looking for a simple way to retrieve the current download speed, any help would be very much appreciated

----------


## JugglingReferee

> Thank you so much for this submission, it's helped me immensely 
> 
> I too am looking for a simple way to retrieve the current download speed, any help would be very much appreciated


Speed is simply data transfered/time interval.

Do you know how to add in code to determine how much data has been received, and how to track how much time has elapsed?

----------


## ph4nt0m

Well, i added a stopwatch and then the following to try to retrieve the current speed



```
currentspeed = iTotalBytesRead / (sTimer.ElapsedMilliseconds / 1000)
```

But it just doesn't seem to return a true speed, i measured it with DU meter and anything past about 300 kb/s seems to go amiss, this calculation is being made on the whole download, not just the chunk, when i tried the same on just a chunk stopping and resetting the stopwatch each loop, it drastically slowed down the download

I also added a counter so that the calculation isn't made on every loop so that the output is still legible to humans (Only updates every 100 loops) but as above, it still slowed the download,

Any further direction or suggestions would be great

----------


## ِِِAkMalkady

*Hi
thank you my brother , it is helpful

I have a question:
how to make a button to stop "downloading" process?? how to cancel the process??

waiting you
thanks*

----------


## ِِِAkMalkady

I did it!!

I added new function named "StopDownload" and new Event "FileDownloadStopped"

download my file : WebFileDownloader.vb

then you can stop download process :


```
_Downloader.StopDownload()
```



```
Private Sub _Downloader_FileDownloadStopped() Handles _Downloader.FileDownloadStopped
       'Write your code here
    End Sub
```

 :Smilie:

----------


## ِِِAkMalkady

> there is a way i can retrieve the download speed?


1 - add "Timer" , Timer1 .. then Set Interval=1000
2 - In general , write :


```
dim lastSize, cSize As Long
```

3 - In "_Downloader_AmountDownloadedChanged" , add :


```
lastSize = cSize
If Timer1.Enabled = False Then Timer1.Enabled = True
```

4 - In Timer1_Tick , write :


```
lblDownloadRate.Text = WebFileDownloader.FormatFileSize(cSize - lastSize)
lastSize = cSize
```

I hope that work fine...

it's work fine with me


your brother:
Abdulkareem
Saudi Arabia, Jazan

----------


## Joke Sparrow

hello thanks for this code..it was very usefull
quick question.. i just want to add webbrowser on this form and if i click the download links on webbrowser it is possible to automatically put the links on txtUrl?

thanks..

----------


## kleinma

in theory yes you could do that. 

I would imagine it would involve handling the navigating event of the browser control and checking the e.url property to see if the type of file being navigated to is one that should be downloaded. Unfortunatly this is probably something that needs to be manually coded to check for extensions (like exe, zip, etc...)

Then once you determine it is a file download, you set e.cancel to true in the navigating event to cancel the browser from doing the download, and you take the e.url property and use that to download using the progress bar downloader class from this thread.

The browser does have a filedownload event, but it does not give you any event arguments to cancel it, so I don't see how it would be useful for this scenario.

----------


## EndLessMind

How to get download speed?
there is e function that count downloaded byte. and i know the 1byte = 8 bit. but how do i make the program to count the byte downloaded every second?

i have open 2 downloader forms. why cant they download a file each at the same time? why do the other wait for the first to finish? and if i opens 3 forms and tired it, then my program stops working.

----------


## ِِِAkMalkady

> How to get download speed?
> there is e function that count downloaded byte. and i know the 1byte = 8 bit. but how do i make the program to count the byte downloaded every second?
> 
> i have open 2 downloader forms. why cant they download a file each at the same time? why do the other wait for the first to finish? and if i opens 3 forms and tired it, then my program stops working.


please read my reply :
http://www.vbforums.com/showpost.php...6&postcount=97

----------


## EndLessMind

well.. that don´nt work for me. i get like "0" or "0 byte" in the label i have to show the speed. 
i dont understand how that would work because lastSize and cSize has no value. you just tell the program the they are going to have the same value.. over and over again. right?

----------


## sanzzes

how can i make the downloader rdy for files more than 7GB i has a file over more than 8GB but it gives me an error with this downloader what must i change in code

----------


## kleinma

I don't know why people love to post something like "it gives me an error" without providing a single detail about the error, yet they expect us to know exactly how to fix the issue.

----------


## sanzzes

> I don't know why people love to post something like "it gives me an error" without providing a single detail about the error, yet they expect us to know exactly how to fix the issue.


The Problem is the ProgBar.Maximum he gives only a integer but i need Int64 for files over 1GB

----------


## kleinma

You just need to use some math to scale down the progress bar values to something acceptible to fall within the bounds of a 32 bit integer since that is what the progress bar takes for its values.

----------


## sanzzes

> You just need to use some math to scale down the progress bar values to something acceptible to fall within the bounds of a 32 bit integer since that is what the progress bar takes for its values.


has you an sample code

----------


## minitech

```
Dim maximum_value As Long = (maximum value)
Dim current_value As Long = (current value)
While maximum_value > Integer.MaxValue
     current_value \= 2
     maximum_value \= 2
End While
Me.ProgressBar1.Maximum = CInt(maximum_value)
Me.ProgressBar1.Value = CInt(current_value)
```

----------


## sanzzes

where must i past this code?

----------


## minitech

Wherever you update the progress bar. I haven't actually looked at the control yet, this was just obvious.

----------


## Legjendat

kleinma is it possible to add the code to some sort of bgworker so that the app doesn't kinda hang every time the dl size gets updated? i have no idea how backgroundworkers work actually but have been told some stuff(they keep the app from going not responding).

----------


## sk8er_boi

nice code... thx for sharing =)

----------


## formlesstree4

@Legjendat: Check my signature for my Asynchronous Downloading File System Class.

----------


## RAJL

kleinma how can I change this application to be able to download files >54K.  The app. is working for my smaller files but on the larger files I receive an error message at statment
 Dim myWebResponse As WebResponse = wRemote.GetResponse
msg- an error occured durning download; a devise attached to the system is not functioning. 
thanks

----------


## matt_wendel

I seriously made an account here JUST to post this post.

I've uploaded a revised version of this class that include summary tags. The only thing that these '''<SUMMARY> tags do is provide a description of the function/sub/property that you are typing within IntelliSense. It makes things MUCH easier. Attached is the revised class file. Import it into your project, and you'll notice that IntelliSence provided a description for the function/sub/property AND its arguments.

Another thing I noticed was the 'Try' and 'Do / Loop' Statements within the class: 


```
Do
                iBytesRead = sChunks.Read(bBuffer, 0, 256)
                FS.Write(bBuffer, 0, iBytesRead)
                iTotalBytesRead += iBytesRead
                If myWebResponse.ContentLength < iTotalBytesRead Then
                    RaiseEvent AmountDownloadedChanged(myWebResponse.ContentLength)
                Else
                    RaiseEvent AmountDownloadedChanged(iTotalBytesRead)
                End If
            Loop While Not iBytesRead = 0
```

This will cause your program to freeze and become unresponsive until the download finishes if you do not run the DownloadWithProgress() on a separate thread. You should use a "BackgroundWorker" and execute this. But before running the BackgroundWorker.RunWorkerAsync(), you have to set the global property 'CheckForIllegalThreadCalls' to FALSE or else an exception will be thrown. Heres an example:


```
CheckForIllegalThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
```

Other then that, this is a very good class. It will come to use for custom install programs, file uploaders/downloaders, file share clients, and much more. Thanks a lot for the class!

----------


## minitech

You should always use Invoke(), BeginInvoke(), etc. instead of just disabling illegal thread call checks unless client-side performance is of the issue.

----------


## matt_wendel

Invoke() and BeginInvoke() are much more difficult to use then a simple backgroundworker. This operation does not include any serious cross-thread calls other then changing some values of progress and file sizes. Unless after the operation is finished, you could re switch the thread call checks back to "true". How would you use Invoke() or BeginInvoke() anyway? i've never used them before.

----------


## JamesVB

i didnt even know you could download stuff with just a progress bar :x

----------


## minitech

> Invoke() and BeginInvoke() are much more difficult to use then a simple backgroundworker. This operation does not include any serious cross-thread calls other then changing some values of progress and file sizes. Unless after the operation is finished, you could re switch the thread call checks back to "true". How would you use Invoke() or BeginInvoke() anyway? i've never used them before.


I'm talking about this:


```
CheckForIllegalThreadCalls = False
BackgroundWorker1.RunWorkerAsync()
```

BackgroundWorker has a method called ReportProgress that uses Invoke in the background - disabling the check for illegal thread calls is not a good practice.

Invoke takes a delegate as a parameter and invokes the delegate on the UI thread.

----------


## eyestrain

wow,
the codes work perfect thank for this sir kleinma,


thanks so much

----------


## ident

Good job kleinma, Iv used your class in my project, Kept all your headers at the top. I assume thats allowed?

My question, downloading a file http://www.file.com/file.exe of course works.

My project is grabbing these types of links. 



```
http://media.soundcloud.com/stream/eRv0K8mcxuUD?stream_token=RlIsi
```

Will download file in a address bar in a browser but not your project. 

Any suggestions on adapting your code to handle these?

edit***

a little url manipulation sorted it

sorry

----------


## stundk@gmail.com

Nicely done kleinma! I have similar questions as ident above, when I entered the following link into the tool:
http://www.vbforums.com/showthread.php?t=396260

I get an error "An error has occurred during download: Illegal characters in path."

What should we modify in the code for the tool to download with those kind of links?

Thanks!!!

----------


## Chris001

It doesn't work, because the last part of the url "showthread.php?t=396260" is used as filename and you can't use question marks in a filename. In that case you'll need to remove the question mark.

Btw, you don't need all this code. You can simply use the WebClient class and download a webpage with three lines of code.


vb.net Code:
Using wClient As New WebClient
    wClient.DownloadFile("URL", "FilePath")
End Using

----------


## stundk@gmail.com

Thanks Chris for your quick response! Based on explanation, I managed to change Function GetFileNameFromURL(ByVal URL As String) As String to remove "?" to make the file name valid. 

Now I will try the three lines of code if it works for me! 

Thanks a lot!

----------


## Brocke

I need a little help and cant figure this out 


Im getting a error at this line 



```
ProgressBar1.Maximum = Convert.ToInt32(iFileSize)
```

it states that the file progress bar max cant be -1 when the download is size of ifilesize is -1 

the file im downloading is 

http://www.mediafire.com/download/2d...r_2012_INT.exe


thank you for you help because im clueless right now lol 

Brock

----------


## Legjendat

> I need a little help and cant figure this out 
> 
> 
> Im getting a error at this line 
> 
> 
> 
> ```
> ProgressBar1.Maximum = Convert.ToInt32(iFileSize)
> ...


It could be because of the fact that, that URL redirects you to another one in order to download the file, and the method you're using to download maybe doesn't support redirecting.

----------


## Brocke

hey guys I need a little help here. 

For some reason I get this error using the download class. 




> The process cannot access the file "" because it is being used by another process


it doesn't happen all the time but im unsure why it happens. 

I've added a stop button but the file only gets deleted if they press the Stop button and when the file get down downloading it starts the file. But not sure why that error comes up once in a while. 

thank you 
Brock

----------


## kleinma

What line of code do you get that error on? the error is pretty self explanatory, some process is holding a handle to that file when you are trying to delete it or append it.

----------


## janu

I have downloaded  WebDownloadWithProgress.zip .. it is really a great source code

I want to use it with my application but need help

I have listview with the items in form load event and each item has a download url associated with  .. like when clicked listview item the url is displayed in checked listview .. how can i use WebDownloadWithProgress with this ...with every listview item different download url is shown in checked listview ..

----------


## skyscraper11

@TS hi i have downloaded your program and it's great, but my problem is i can't download files bigger than 20 MB, just like what you have said, but i have no idea on what i'm going to do to the solution that you were saying. can you help me please? I'm having an error that says _Arithmetic operation resulted in an overflow._

----------


## jdc20181

> Here is a sample project I did up that uses a class I wrote (WebFileDownloader)
> 
> The WebFileDownloader class provides methods for downloading a file from a URL and firing events to update progress in the GUI on a progress bar or whatever you may like. 
> 
> The standard WebClient class in the .NET framework has a method for downloading a file, but there is no indication of its progress as it downloads, which is why I wrote this up.
> 
> Known limitations:
> progress is returned as a long, and a progress bar takes an integer, so in the sample I convert the long to integer, which could error in BIG downloaded files.. a better solution would be to use the filesize being downloaded and calculate a good maximum to set the progress bar to. However this is GUI related, and not related to the WebFileDownloader class itself. (Just wanted to point it out)
> 
> ...


I haven't looked at the code (this is older i know) but, couldnt you whereever your code is be something like this (using navigate for example)



```
webbrowser1.navigate("http://" + Url.text)
```

also dunno if anyone has suggested this before - Thanks!

----------


## szlamany

Thanks Matt - I'm using your code - in a big old SQL loop - to pull 14,000 PDF's off of a site.  Working like a charm!

----------

