James Aharon
James Aharon

Reputation: 223

How to check if file downloaded successfully in Webclient DownloadFileCompleted event?

private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
}

I want to check these two cases:

  1. If there was an error then do something.

  2. If the file was downloaded successfully do something.

Upvotes: 0

Views: 3187

Answers (1)

Yurii
Yurii

Reputation: 4911

You can examine the Error and Cancelled properties of the AsyncCompletedEventArgs instance:

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

Upvotes: 2

Related Questions