2014-10-04 59 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 
}