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
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
Here is the full codes
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 .
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
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
Replythis is not wrking
ReplyIt worked for me that's why I wrote this tutorial. Do you get any errors?
ReplyTechnology 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.
ReplyFor Design and development have a look to Hire Magento Developers
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.
ReplyElevate Computers and IT Solutions Mackay
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#.
ReplyMobile Website Design
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
ReplyThis 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.
ReplyJust 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
that was really good information
Replynice job author,
most exclusive training on seo given at affordable price
get seo training today seo training in bangalore
Very helpful post, definitely going to try this one. Wondering if you could provide a chat tutorial too.
ReplyWebsite designing company in Delhi
Facilitated Interactive Voice Response IVR preferences are being opened for some endeavor situations by new voice over Internet Protocol (VoIP) based IVR Applications
Replythat was really good information
Replynice job author.Very helpful post, definitely going to try this one.
digitalopeners
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.
Replydigitalopeners.com
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
ReplyIn 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.
ReplyWeb Design Services Company in Jaipur- http://bit.ly/2jWr2dY
Thanks for sharing an Informative blog with us, Keep updating to get knowledge from your website.
ReplyWe 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.
Post a Comment
Note: Only a member of this blog may post a comment.