用webclient downloadfile c#覆盖文件

时间:2015-12-09 15:30:02

标签: c# webclient-download downloadfile

我在C#中使用Webclient.DownloadFile()来保存一些文件。如果文件已经存在,我想覆盖它。 如果该文件存在,该方法是否会覆盖该文件? 到目前为止,似乎没有覆盖它 感谢

2 个答案:

答案 0 :(得分:0)

这是一个棘手的问题吗?

if (File.Exists(myFile))
{
    File.Delete(myFile);
}

答案 1 :(得分:0)

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

如果再次下载,此代码会覆盖文件。