Willcode4cash icon

SaveUrlFileData

Willcode4cash | PRO | 09/17/16 05:25:56 AM UTC | 0 ⭐ | 263 👁️ | Never ⏰ | []
C# |

490 B

|

None

|

0 👍

/

0 👎

private void SaveUrlFileData(string url, string destination, bool overwrite = false)
{
    var fileParts = url.Split(new[] {'/'}, StringSplitOptions.RemoveEmptyEntries);
    destination = string.Concat(destination, "\\", fileParts.Last());
    
    using (WebClient client = new WebClient())
    {
        client.ForgeHeaders();
        Console.WriteLine($"Downloading {destination}");
        if ((overwrite && File.Exists(destination)) || !File.Exists(destination))
        {
            client.DownloadFile(url, destination);
        }
    }
}

Comments