2014-10-04 68 views
0
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e) 
{ 
} 

我要检查这两种情况下:如何在Webclient DownloadFileCompleted事件中检查文件是否成功下载?

  1. 如果有一个错误,然后做一些事情。

  2. 如果文件成功下载,请执行一些操作。

+1

检查[这](http://stackoverflow.com/questions/13917009/web-client-downloadfilecompleted- get-file-name)可以帮助你解决问题 – 2014-10-04 11:19:35

+0

文件是否来自你控制的源文件? – 2014-10-04 11:29:54

回答

2

您可以检查AsyncCompletedEventArgs实例的ErrorCancelled属性:

if (e.Error != null) 
{ 
    // there was an error, do something 
} 
else if (!e.Cancelled) 
{ 
    // file was downloaded fine and completed, do something 
}