DownloadStringAsync返回错误,使用url下载文件

时间:2014-03-03 10:10:26

标签: c# windows-phone-8

当我使用带有webclient的DownloadStringAsync时,它给出了我如何解决这个问题的错误

 private  void BtnDownload_Click(object sender, RoutedEventArgs e)
    {
               //string PDFPath = ((((sender as Button).Content) as StackPanel).Children[1] as TextBlock).Text;
               string PDFPath = "http://www.ncu.edu.tw/~ncu25352/Uploads/20131231103232738561744.pdf";
               pdffile = PDFPath;

               WebClient wb = new WebClient();
               wb.DownloadStringCompleted += wb_DownloadStringCompleted;
               wb.DownloadStringAsync(PDFPath,"pdfnamefile");
    }

    void wb_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
    {
        throw new NotImplementedException();
    }

1 个答案:

答案 0 :(得分:2)

首先,你应该给我们确切的错误。

这个答案假定你得到了NotImplementedException

您收到此错误是因为您自动生成了wb_DownloadStringCompleted处理程序并且未删除throw子句。

因此,只要下载完成,您就会自己解雇NotImplementedException。事实上,一切都很好。

试试这段代码:

void wb_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
{
     //What you want to do
}

然后添加你的说明。