ellapt

T12.4.ReadFileFromInternet

Jan 25th, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. class ReadFileFromInternet
  2. {
  3. static void Main()
  4. {
  5. Console.WriteLine("Write a program that downloads a file from Internet\ne.g. http://www.devbg.org/img/Logo-BASD.jpg)\nand stores it into the current directory of the project:\n");
  6. using (WebClient webFile = new WebClient())
  7. {
  8. try
  9. {
  10. webFile.DownloadFile("http://www.devbg.org/img/Logo-BASD.jpg", "../../logoBASD.jpg");
  11. Console.WriteLine("The file was successfully loaded");
  12. }
  13.  
  14. catch (WebException)
  15. {
  16. Console.Error.WriteLine("The address is invalid.");
  17. }
  18.  
  19. catch (NotSupportedException)
  20. {
  21. Console.Error.WriteLine("The method has been called simultaneously on multiple threads.");
  22. }
  23. catch (InvalidOperationException)
  24. {
  25. Console.Error.WriteLine("File ../../logoBASD.jpg is open by another program.\nPlease, close it and try again!");
  26. }
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment