The WebClient class is obviously designed to suppress a lot of detail and control. You can write your own method to download the file asynchronously very easily and control how the downloaded data is written to disk.
I know for sure that this solution in codeproject contains a class that loads a file using WebRequest and WebResponse , which allows a lot more control. See A class containing the name webdata . Code you can pay attention to:
FileStream newFile = new FileStream(targetFolder + file, FileMode.Create); newFile.Write(downloadedData, 0, downloadedData.Length); newFile.Close();
FileMode Enumeration contains a number of members that dictate the FileMode.CreateNew file save behavior, will throw an IOException if the file already exists. Like where FileMode.Create will overwrite files if possible.
If you insist on using WebClient.DownloadFileAsync , then, as other guys have already noted, you can simply tell the user that the existing file will be overwritten with OpenFileDialog , but some downloads can take a long time and there is nothing to say that the user did not create another file at boot time.
Caster troy
source share