C# Downloading a file does not work

touyets picture touyets · Jun 28, 2013 · Viewed 11.3k times · Source

Using code below but it is not downloading any file at all to the specified subfolder named myImages to the application... How can I fix this? The link is purely an example here, usually the link will be a variable and that has no issue populating itself. This is all being done in a BackgroundWorker that works 100% fine otherwise.

//File to download
string _fileToDownload = "http://www.codeproject.com/images/download24.png"
//Path to download files
string _filePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "MyImages\\download24.png'";
//Download the image
using (var webClient = new WebClient())
{
    webClient.DownloadFileAsync(new Uri(_fileToDownload ), @_filePath);
}

Thanks.

Answer

touyets picture touyets · Jun 28, 2013

Ok. emmmmmmmmm found my answer: indeed I can use the filedownload method but it would have been useful for me to enter the correct save path... this was the correct path, I forgot to put a \ before my folder name....

string _filePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\MyImages\\download24.png'";