简体   繁体   中英

overwrite a file with webclient downloadfile c#

I'm using Webclient.DownloadFile() in C# to save some files. If the file already exists i want to overwrite it. Does this method overwrite a file if it exists?? It Doesn't seem to be overwriting it so far.
Thanks

Is this a trick question?

if (File.Exists(myFile))
{
    File.Delete(myFile);
}
using (WebClient client = new WebClient())
{
    client.DownloadFileAsync(new Uri("http://test.com/exe.rar"), @"C:\exe.rar");
}

this code overwritten file if downloaded again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM