# VBForums CodeBank > CodeBank - Visual Basic .NET >  WebClient DownloadFileAsync with resume support

## Chris001

Here's a simple DownloadFileAsync class that allows resuming and also returns a few extra properties, like download speed, download time and remaining time. You can specify the update frequency (no delay, every 500ms or every second), so the ProgressChanged event doesn't fire continuously and hog CPU when updating controls.

The added example also shows you how to create an ownerdrawn ListView, so you can draw a custom progressbar, in order to show the download progress.

This version only supports Http downloads, because that's what most people use DownloadFileAsync for.

The DownloadFileAsyncExtended, HttpWebRequestState, FileDownloadProgressChangedEventArgs and FileDownloadCompletedEventArgs classes have been added to a single file for convenience. You might want to put each class in its own file.

I'm sure there are a few things that can be improved, so comments are welcome.

I had to remove all executables from the project before posting it here. You might get a warning "Could not find type 'SampleProject.ListViewExtended'". In that case, Build the sample project first and restart the project.

----------


## stru4nak

nice project

----------


## janu

Thanks , Very Nice but something is missing there .. when we close the application with resuming half download of any file .. in next attempt it is not there .. please add after resuming if application is closed in next attempt we should be promoted to continue previous resumed download..

----------


## formlesstree4

> Thanks , Very Nice but something is missing there .. when we close the application with resuming half download of any file .. in next attempt it is not there .. please add after resuming if application is closed in next attempt we should be promoted to continue previous resumed download..


Of course it's not there; the program doesn't know you want to keep it. Granted, you can do that [there are Downloading Applications out there that do such a thing], it just requires a bit more code.

----------


## Chris001

> Thanks , Very Nice but something is missing there .. when we close the application with resuming half download of any file .. in next attempt it is not there .. please add after resuming if application is closed in next attempt we should be promoted to continue previous resumed download..


Sorry, but I'm not going to add that. It seems you have misunderstood what this code is about. The normal WebClient class rejects the Range header, preventing you from downloading only a part of the file, thus resuming. This class allows you to download files, just like you would do with the normal WebClient class, but this one supports resuming.

The included project is just a Sample Project, that simply shows you how to use the download class and nothing more. Remembering partially finished downloads and other features is something you'll have to add yourself... you are the programmer  :Wink:

----------


## jomamano

Thanks for this.  I learned a LOT from it.  I program in C# and was using WebClient to transfer files between PCs around the country in our network.  I found you by Googling about doing resumes.  
- You got me to switch to HttpWebRequests
- I converted your DownloadFileAsyncExtended.vb to a C# version using http://www.developerfusion.com/tools.../vb-to-csharp/ (not bad!) and some tweaks
- The passing around of ListViewItems sure made my job easier
- I also like storing the DownloadFileAsyncExtended objects in the ListViewItem Tags.  I often have a problem figuring out how to trace my steps and find out where I'm coming from
- Hate to admit it, but I'd never used SmallImageList before.  Very cool.
- This is a really great foundation for extending it to do resumes after restarting.  My basic setup on this project is to try to keep files at remote sites in sync with "local" files

Just wanted to thank you for sharing your work.  I don't take the time to do that enough in this generous online community of programmers we have on the Internet.

----------


## chekhov

excellent project, thank you. I translated it to C#,  http_multiDownloader.zip attached is the Visual Studio 2010 solution in C#

----------


## babythong

Can I use this code in my project?

----------


## Chris001

> Can I use this code in my project?


Yes, you are free to do with it whatever you want.

----------


## babythong

Thank you very much !  :Smilie:

----------


## LastSoul

Nice Its Very Good Project^^

----------


## Brocke

when I try to download the project it just downloads a file named attachment.php

how can I download the sample project?

----------


## Chris001

Try to right-click on the link and select "Save Link As...", "Save Target As..." or something like that, depending on which browser you use.

----------


## softwareguy74

Dang, I wish I saw this earlier!  I was working on my own.  Thanks for doing this awesome work!

----------


## Mohammad Element

Very Niceeeeee,TNX  :Wink:

----------


## Noob13

Great Thank you very Much  :Smilie:

----------


## Noob13

what should I do For make it Resume exist file !?
I`m Trying to make it save list items when Close and resume if Open it again
I`m Sticking with this Problem !
I Give it same File name and I Active ResumeAsync



```
If _ResumeAsync Or AResumeAsync Then
            'If _ResumeAsync Then
            Dim FileInfo As New FileInfo(LocalFilePath)
            If FileInfo.Exists Then
                Request.AddRange(FileInfo.Length)
            End If
        End If
```

its rewrite file and start from beginning !
Thank for advice

----------


## Noob13

I`m Trying to Complete This Project
I Active [ _CancelAsync = True ] For Stop rewrite uncompleted file
and Save&Load ListViewEx.Items Info
Please Post Your opinion For Help Complete it
Thank You!

----------


## CrazyCode139

Hi Chris001 ;
I thank you a lot for this perfect work.
Please accept my respect

----------

