使用下面的代碼,但它根本沒有下載任何文件到名爲myImages的指定子文件夾到應用程序......我該如何解決這個問題?這裏的鏈接純粹就是一個例子,鏈接通常是一個變量,並且沒有任何問題。這一切都是在BackgroundWorker中完成的,否則將100%正常工作。C#下載文件不起作用
//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);
}
謝謝。
它不想工作。我在一個已經運行的後臺工作者中使用代碼,並且當我將其更改爲非異步方法進行下載時,它說我的後臺工作已完成(這是錯誤的,因爲它應該工作一段時間)。 ..這隻發生在DownloadFile方法而不是ASync方法,但ASync方法不會下載任何東西 – touyets