How To Make A Downloader In C#

How To Make A Downloader Picture
Making your own downloader (simple download) would sound hard and maybe boring but actually it's not , it's very easy to make a downloader in c# . Today i will tell you how to write downloader in c# in the easiest way by the way this is just a simple one .

First of all create a new project then add two buttons, two text boxes, two labels & at last add a progressbar now change the properties of your tools as given below

Button1 - Text : Download
Button2 - Text : Save
Label1 - Text : Direct Link(Optional)
Label2 - Text : Save File(Optional)
Textbox1 - To Put The Download Link
Textbox2 - To Show The Save Directory

Arrange the tools to make your form look like this
Arranging Form
Now we'll start coding , First go ahead and add the namespace using System.Net; then go to button1(Download) click_event and code these
 if (textBox2.Text == String.Empty)//having a if statement to make the program more comfort
            {
                MessageBox.Show("Please select a destination to save the file");
            }
            else
            {
                WebClient Download_Client = new WebClient();//Declaring the webclient as Download_Client
                Download_Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);//the event handler
                Download_Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);// " "
                Download_Client.DownloadFileAsync(new Uri(textBox1.Text.Trim().ToString()), textBox2.Text.Trim());// " "
            }
Then go to ProgressChanged event and add this bit of code(Mind the handler)
   private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
 MessageBox.Show("Downloading Successful " , "Download_Completed" ,MessageBoxButtons.OK ,MessageBoxIcon.Information);//just a messagebox           
            progressBar1.Value = (0);//resetting the progressbar
            textBox1.Text = "";//restting the textbox
            textBox2.Text = "";// " "
        }
Now the AsyncCompleted Event
  private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Downloading Successful " , "Download_Completed" ,MessageBoxButtons.OK ,MessageBoxIcon.Information);//just a messagebox           
        }
Now at last open the button2_click event(Save) and code these
  FolderBrowserDialog Save = new FolderBrowserDialog();//Declaring the folder browsing dialog
            Save.RootFolder = Environment.SpecialFolder.Desktop;//" "
            if (Save.ShowDialog() == DialogResult.OK)//An if statement to to show the path in textbox
            {
                textBox2.Text = Save.SelectedPath;
            }
            string Text = textBox1.Text.ToString();//formatting to string
            string[] arry = Text.Split('/');//splitting /
            for (int i = 0; i < Int32.Parse(arry.Length.ToString()); i++)//a for loop here
            {
                if (i == Int32.Parse(arry.Length.ToString()) - 1)
                {
                    textBox2.Text += "\\" + arry[i].ToString();
                }
             }

Here is the full codes
//Author : Mohamed Shimran
        //Blog : http://ultimateprogrammingtutorials.blogspot.com
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == String.Empty)//having a if statement to make the program more comfort
            {
                MessageBox.Show("Please selet a destination to save the file");
            }
            else
            {
                WebClient Download_Client = new WebClient();//Declaring the webclient as Download_Client
                Download_Client.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);//the event handler
                Download_Client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);// " "
                Download_Client.DownloadFileAsync(new Uri(textBox1.Text.Trim().ToString()), textBox2.Text.Trim());// " "
            }
        }
        private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
        {
            progressBar1.Value = e.ProgressPercentage;//setting the progressbar value as downloadprogress
        }
        private void Completed(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("Downloading Successful " , "Download_Completed" ,MessageBoxButtons.OK ,MessageBoxIcon.Information);//just a messagebox           
            progressBar1.Value = (0);//resetting the progressbar
            textBox1.Text = "";//resetting the textbox
            textBox2.Text = "";// " "
        }

        private void button2_Click(object sender, EventArgs e)
        {       
            FolderBrowserDialog Save = new FolderBrowserDialog();//Declaring the folder browsing dialog
            Save.RootFolder = Environment.SpecialFolder.Desktop;//setting to desktop
            if (Save.ShowDialog() == DialogResult.OK)//An if statement to to show the path in textbox
            {
                textBox2.Text = Save.SelectedPath;
            }
            string Text = textBox1.Text.ToString();//formatting to string
            string[] arry = Text.Split('/');//splitting /
            for (int i = 0; i < Int32.Parse(arry.Length.ToString()); i++)//a for loop here
            {
                if (i == Int32.Parse(arry.Length.ToString()) - 1)
                {
                    textBox2.Text += "\\" + arry[i].ToString();
                }
             }
        }

Let's test the application by the way you can only download from direct links .
Test the program on your own , I hope this is useful .

17 comments

In today's technology any application is easily developed because of have great features, like C# is used in .net for more security and user friendly website, looking for start online business .net is good web development that able to create any kind of application - web designing company in Jaipur

Reply

It worked for me that's why I wrote this tutorial. Do you get any errors?

Reply

Technology is changing day by day and HTML5 is more easy and user friendly along with making a website more Google friendly in more simple way.
For Design and development have a look to Hire Magento Developers

Reply

One of the best part for web development is using the html5 and css3 as Google gives more preference to the simple websites instead of any other.
Elevate Computers and IT Solutions Mackay

Reply

C# is simple, modern and general purpose object oriented programming language. It is developed by Microsoft team members. It is embedded with .net programming language. This blog also provides more information about c#.
Mobile Website Design

Reply

Very good written post. It will be helpful to anyone who usess it, including me. Keep doing what you are doing - looking forward to more posts.web design jaipur

Reply

This was a really helpful article for me. I\'ve been writing a batch download program and I was getting a bit stuck with the progress bar idea.

Just one thing I would suggest. Once you get the file size from the HttpWebResponse object, it should probably be closed there and then. I ran into timeout issues with the second file in my batch. I isolated the closing of the web response and after I fixed that, all was good.

web development company in jaipur

Reply

that was really good information
nice job author,

most exclusive training on seo given at affordable price
get seo training today seo training in bangalore

Reply

Very helpful post, definitely going to try this one. Wondering if you could provide a chat tutorial too.
Website designing company in Delhi

Reply

Facilitated Interactive Voice Response IVR preferences are being opened for some endeavor situations by new voice over Internet Protocol (VoIP) based IVR Applications

Reply

that was really good information
nice job author.Very helpful post, definitely going to try this one.
digitalopeners

Reply

Sometime in 2004 on Geekpedia we saw a tutorial entitled Using WebClient to download a file, where we would use a few lines of code to save a file retrieved from the web through http on our hard drive. Now we're taking one step forward, to complicate the things just a little, so that we can display the progress of the download.
digitalopeners.com

Reply
This comment has been removed by the author.

After a long time we are noticing something so good and enticing available on smartphones. There have been some questions regarding its features, so let’s discuss them and how to use it precisely. obat ginjal bengkak

Reply

In today's technology any application is easily developed because of have great features like C#, php, HTML5 and So many. It will be helpful to anyone who usess it, including me.

Web Design Services Company in Jaipur- http://bit.ly/2jWr2dY

Reply

Thanks for sharing an Informative blog with us, Keep updating to get knowledge from your website.

We are a web design company in USA. Our London website design services use our creative website designers skills too offer Affordable Web Design Services USA & Affordable eCommerce Website Design Services USA.

Reply

Post a Comment

Note: Only a member of this blog may post a comment.