Click here to Skip to main content
13,043,491 members (48,877 online)
Click here to Skip to main content
Add your own
alternative version


91 bookmarked
Posted 28 Jun 2007

HTTP File Downloader Class for .NET

, 23 Sep 2007
Rate this:
Please Sign up or sign in to vote.
HTTP File Downloader Class for .NET (HTTPFileDownloader)
Screenshot - FileDownloader.gif


This short article presents the component HttpFileDownloader for .NET. It was designed a few years ago, that is why it is written for .NET 1.1. However it can be used for newer Frameworks and/or recompiled. It shows the estimated time left and the progress. The component can be used with Windows forms application and with console/service apps.
If used in a windowless environment, null should be passed to the constructor instead of this. The code is very simple to use and understand.

Using the Code

Create the instance of the component and the event handler.

_FileDownloader = new DotNetFileDownloader(this); 
// "this" required only for Windows Forms Component/App 
_FileDownloader.URLDownload = textBox_url.Text; // set the URL to download
// setting local path
_FileDownloader.LocalFilePath = textBox_local_folder.Text + "\\" + FileName ;

// setting the downloading status event handler
_FileDownloader.UpdateStatusEvent +=new UpdateDelegate(

The status event handler is pretty straightforward:

string Message, 
DStatus Status, 
long FullSize, 
long CurrentBytes, 
TimeSpan EstimatedTimeLeft)
    label_status.Text = Message + "\n" + Status.ToString();
    if (FullSize != 0 && FullSize != -1)
        this.progressBar1.Value = (int)(((double)CurrentBytes / (double)FullSize) * 100);

        // display total Kbytes and current Kbytes
        label_curr_bytes.Text = CurrentBytes.ToString() + " Kb of " +
            FullSize.ToString() + " Kb"; 

    if ((Status == DStatus.complete) || 
        (Status == DStatus.failed) || 
        (Status == DStatus.aborted))
            button_start.Enabled = true;
            button_stop.Enabled = false;
    // displaying estimated time left
    label_estimated_time.Text = "Estimated time left";
    string stmp = EstimatedTimeLeft.ToString();
    stmp = stmp.Substring(0, stmp.IndexOf('.'));
    label_estimated_time.Text = "Estimated time left : " + stmp; 

If required, it can download through the proxy (with user name and password). The downloading can be aborted at any time because it runs in the worker thread.

Points of Interest

If a newer version of this component is released, it can be found here along with other useful classes and components.


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


About the Author

Web Developer
Australia Australia
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralThis component has been superseded by HttpDownloaderControl Pin
Alex_115-Jul-08 14:17
memberAlex_115-Jul-08 14:17 
Generalquestion Pin
jkersch24-Sep-07 0:08
memberjkersch24-Sep-07 0:08 
GeneralCool Pin
RunnerDude6-Jul-07 8:30
memberRunnerDude6-Jul-07 8:30 
GeneralLooks good Pin
Tmefjhf28-Jun-07 16:30
memberTmefjhf28-Jun-07 16:30 
GeneralRe: Looks good Pin
rohim.yasin4-Jul-07 2:04
memberrohim.yasin4-Jul-07 2:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 23 Sep 2007
Article Copyright 2007 by Alex_1
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid