1. using System;
  2. using System.ComponentModel;
  3. using System.Net;
  4. namespace ConsoleApplication3
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string file = "test.file";
  11. try
  12. {
  13. WebClient wc = new WebClient();
  14. FileInfo f = new FileInfo(Environment.CurrentDirectory + "/" + file);
  15. wc.Headers.Add(HttpRequestHeader.Range, "bytes=-" + f.Length.ToString());
  16. wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
  17. wc.DownloadFileAsync(new Uri("http://site/" + file), Environment.CurrentDirectory + "/" + file, file);
  18. Console.WriteLine("Downloading...");
  19. Console.ReadKey();
  20. }
  21. catch(Exception e)
  22. {
  23. Console.WriteLine("Error:: " + e.Message);
  24. Console.ReadKey();
  25. }
  26. }
  27. static void DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
  28. {
  29. Console.Clear();
  30. Console.WriteLine("Загружено: \n " + (string)e.UserState + " => " + e.BytesReceived + " / " + e.TotalBytesToReceive + " (" + e.ProgressPercentage + "%)");
  31. Console.ReadKey();
  32. }
  33. }
  34. }
Comments powered by Disqus