我的代码如下。我正在尝试下载一个文件,我的应用程序给了我“文件名未找到 - 下载”,后面跟着“完成”这个代码的结果,但是当我去看看没有文件实际上已被下载。
private void Form1_Load(object sender, EventArgs e)
{
download(@"mp3spi.jar", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\.minecraft\bin\lob\");
}
public void download(String filename, String path)
{
filenameLabel.Text = filename;
MessageBox.Show(filename + " Not found - downloading.");
WebClient webClient = new WebClient();
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
webClient.DownloadFileAsync(new Uri("http://mysite.com/client/" + filename), path);
}
public void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
progressBar1.Value = e.ProgressPercentage;
}
private void Completed(object sender, AsyncCompletedEventArgs e)
{
MessageBox.Show("Finished.");
}
有人能指出我的错误吗?我想也许它需要以管理员身份运行,但这只是做了同样的事情。
答案 0 :(得分:2)
您的代码尝试保存到文件夹路径(“... \ lob \”),这不是文件名,如(... \ lob \ my_file.ext“)。
WebClient.DownloadFileAsync(Uri Uri address, string fileName)