lundi 11 septembre 2017

c# webclient.DownloadFile

I would like to know how to check if the file exists before downloading.

current code

string url = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "/text.txt";
string path = "http://ift.tt/2wWu5bi";

using (var client = new WebClient())
    {
        client.DownloadFile(url, path);
    }

the code works but if the file is missing on the site it creates a empty text.txt that causes issues

any ideas? thank you




Aucun commentaire:

Enregistrer un commentaire