Advertisement
Willcode4cash

SaveUrlFileData

Sep 17th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.49 KB | None | 0 0
  1. private void SaveUrlFileData(string url, string destination, bool overwrite = false)
  2. {
  3.     var fileParts = url.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
  4.     destination = string.Concat(destination, "\\", fileParts.Last());
  5.    
  6.     using (WebClient client = new WebClient())
  7.     {
  8.         client.ForgeHeaders();
  9.         Console.WriteLine($"Downloading {destination}");
  10.         if ((overwrite && File.Exists(destination)) || !File.Exists(destination))
  11.         {
  12.             client.DownloadFile(url, destination);
  13.         }
  14.     }
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement