Webclient C# 异步下载完成后获取文件路径
Webclient C# get filePath after completing async download
我有这个方法:
public void downloadClip()
{
using (WebClient wc = new WebClient())
{
//Download
wc.DownloadFileCompleted += Wc_DownloadFileCompleted;
string file_name_ender = @"My\Path";
wc.DownloadFileAsync(new System.Uri(@downloadUri), file_name_ender);
}
}
然后我有这个 DownloadFileCompleted:
private void Wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
//I need to get where file was downloaded to
}
然后我需要进入这个说明我下载文件的位置的方法字符串。基本上我的 file_name_ender
.
感谢您的帮助。
使用第二种重载方法:
wc.DownloadFileAsync(uri, file_name_ender, file_name_ender);
然后就可以从事件中的UserState属性中获取值了:
private void Wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
var filename = (string)e.UserState;
}
我有这个方法:
public void downloadClip()
{
using (WebClient wc = new WebClient())
{
//Download
wc.DownloadFileCompleted += Wc_DownloadFileCompleted;
string file_name_ender = @"My\Path";
wc.DownloadFileAsync(new System.Uri(@downloadUri), file_name_ender);
}
}
然后我有这个 DownloadFileCompleted:
private void Wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
//I need to get where file was downloaded to
}
然后我需要进入这个说明我下载文件的位置的方法字符串。基本上我的 file_name_ender
.
感谢您的帮助。
使用第二种重载方法:
wc.DownloadFileAsync(uri, file_name_ender, file_name_ender);
然后就可以从事件中的UserState属性中获取值了:
private void Wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
var filename = (string)e.UserState;
}