WebClient - DownloadFileCompleted访问404 URL

时间:2013-02-14 13:56:01

标签: c# .net webclient

我用 private void已完成

public void DonwloadFile()
{
    WebClient webClient = new WebClient();
    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
    webClient.DownloadFileAsync(new Uri("resource to download"), reportFileName );
}
   private void Completed(object sender, AsyncCompletedEventArgs e)
        {

            //do some stuff
        }

这样可行,但如果“要下载的资源”不可用(返回404),则会在“reportFileName”处创建一个空文件。我可以在Completed中检查AsyncCompletedEventArgs并查看异常,但之后已经创建了空文件。

有没有办法以不创建空文件的方式处理404?

0 个答案:

没有答案