Advertisement
Martichka

Exception Handling/ Task - 4 File From Web

Jan 27th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. class FileFromInternet
  4. {
  5.     static void Main()
  6.     {
  7.         Console.Write("Enter web address to download file from: ");
  8.         string address = Console.ReadLine();
  9.         Console.Write("Enter full path where to download and file name at the end: ");
  10.         string file = Console.ReadLine();
  11.         string fullAddress = address + "," + file;
  12.         WebClient webClient = new WebClient();
  13.         try
  14.         {
  15.             webClient.DownloadFile(fullAddress, file);
  16.             Console.WriteLine("Download is finished!");
  17.         }
  18.         catch (ArgumentNullException)
  19.         {
  20.             Console.WriteLine("The address can not be null");
  21.         }
  22.         catch (NotSupportedException)
  23.         {
  24.             Console.WriteLine("This method does not support simultaneous downloads.");
  25.         }
  26.         catch (WebException)
  27.         {
  28.             Console.WriteLine("Wrong web addres or destination folder.");
  29.         }
  30.         finally
  31.         {
  32.             webClient.Dispose();
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement