I am writing an importer in C# for an XML file. Every time I run the import I need to download the XML file from a URL.
I have wirtten the following code to download it:
var xmlPath = @"C:\Desktop\xxx.xml";
public void DownloadFile(string url, string saveAs)
{
using(var webClient = new WebClient())
{
webClient.DownloadFileAsync(new Uri(url), saveAs);
}
}
and _downloader.DownloadFile(Config.FeedUrl, xmlPath);
to call the method. The Url is in the config file (Config.FeedUrl
).
Then when I am trying to GetProperties(xmlPath);
I get the Exception "Process Cannot access the file because the file is being used by another process.
I made sure that the destination exists but I am not sure why I get this error.