This article describes an All-In-One Code Framework sample that is available for download. This code sample demonstrates how to build a basic file downloader that shows the progress of the download.
The System.Net.WebClient class in this code sample has a DownloadProgressChanged event. You can register this event to show download progress. However, the System.Net.WebClient class does not support the pause and resume functions.
This code sample could be used to download data from an internet. Also, this code sample supports the following features:
Difficulty level
Note To do this, the server must support the Accept-Ranges header.
Note For more information about how to create and deploy the sample application, see the Readme.txt file that is included in the download package.
For more information about the AddRange method, visit the following MSDN website:
For more information about how to check whether a file download has completed, visit the following MSDN website:
The System.Net.WebClient class in this code sample has a DownloadProgressChanged event. You can register this event to show download progress. However, the System.Net.WebClient class does not support the pause and resume functions.
This code sample could be used to download data from an internet. Also, this code sample supports the following features:
- Download a specified block data for the whole file.
- Start, pause, resume and cancel a download.
- Set the buffer and cache size.
- Show the progress during the download.
Difficulty level

Download information
To download this code sample, click one of the following links:Technical overview
Download a specific block of data from a file
To download a specific block of data, use the AddRange method of the System.Net.HttpWebRequest class to add a byte range header to a request. You can use the following syntax to call the AddRange method:Public void AddRange (int from, int to)
Note To do this, the server must support the Accept-Ranges header.
Pause and resume a download
The HttpDownloadClient class can be used to start, pause, resume and cancel a download. If the download function is paused, the number of bytes that have been downloaded is stored. If the download function is resumed, the file will resume downloading from the same location in which the download was paused.Set the buffer and cache size
After you set the buffer and cache size, the downloaded data is stored in a MemoryStream first, and then written to a local file.Show the progress during the download
When a specified number of bytes of data is downloaded, the HttpDownloadClient class fires a DownloadProgressChanged event. If the download is completed or canceled, the class will also fire a DownloadCompleted event. The MainForm class registers these two events and shows the download progress.Note For more information about how to create and deploy the sample application, see the Readme.txt file that is included in the download package.
Languages
This code sample is available in the following programming languages:Language | Project Name |
---|---|
Visual C# | CSWebDownloader |
Visual Basic.NET | VWebDownloader |
Prerequisites
This sample application was created using Microsoft Visual Studio 2010 and Microsoft .NET Framework 4.References
For more information about the HttpWebRequest class, visit the following Microsoft Developer (MSDN) website:For more information about the AddRange method, visit the following MSDN website:
For more information about how to check whether a file download has completed, visit the following MSDN website: