Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Text;
- namespace _04DownloadFile
- {
- class DownloadFile
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the url of the file which you want to download: (ex: http://www.devbg.org/img/Logo-BASD.jpg)");
- string path = Console.ReadLine();
- Console.WriteLine("Enter where to be saved the file and its name: (ex. C:\\Downloads\\pic.jpg)");
- string fileName = Console.ReadLine();
- WebClient Client = new WebClient();
- try
- {
- Client.DownloadFile(path, fileName);
- Console.WriteLine("The file was downloaded");
- }
- catch (HttpListenerException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (WebException ex)
- {
- Console.WriteLine(ex.Message);
- }
- catch (UriFormatException ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment