The WebClient
class is obviously designed to suppress a lot of detail and control. You can write your own method to asynchronously download a file very easily and control how the downloaded data is written to disc.
I know for sure that this solution at codeproject contains a class which downloads a file using WebRequest
and WebResponse
which allows for much more control. See the class contained named webdata
. The code you can need to pay attention too:
FileStream newFile = new FileStream(targetFolder + file, FileMode.Create);
newFile.Write(downloadedData, 0, downloadedData.Length);
newFile.Close();
The FileMode Enumeration
contains a series of members that dictate the behaviour of saving a file FileMode.CreateNew
will throw an IOException
if a file already exists. As where FileMode.Create
will overwrite files if possible.
If you insist on using WebClient.DownloadFileAsync
then, as the other fellas have already mentioned: you can just inform the user that an existing file will be overwritten by means of an OpenFileDialog
but some downloads can be time consuming and there's nothing to say that the user has not created another file during the download.