TodorMitev

DownloadFile

Jan 22nd, 2012
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6.  
  7. namespace _04DownloadFile
  8. {
  9.     class DownloadFile
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.WriteLine("Enter the url of the file which you want to download: (ex: http://www.devbg.org/img/Logo-BASD.jpg)");
  14.             string path = Console.ReadLine();
  15.             Console.WriteLine("Enter where to be saved the file and its name: (ex. C:\\Downloads\\pic.jpg)");
  16.             string fileName = Console.ReadLine();
  17.             WebClient Client = new WebClient();
  18.             try
  19.             {
  20.                 Client.DownloadFile(path, fileName);
  21.                 Console.WriteLine("The file was downloaded");
  22.             }
  23.  
  24.             catch (HttpListenerException ex)
  25.             {
  26.                 Console.WriteLine(ex.Message);
  27.             }
  28.             catch (WebException ex)
  29.             {
  30.                 Console.WriteLine(ex.Message);
  31.             }
  32.             catch (UriFormatException ex)
  33.             {
  34.                 Console.WriteLine(ex.Message);
  35.             }
  36.         }
  37.     }
  38. }
Add Comment
Please, Sign In to add comment