私は現在、小さな研究プロジェクトのために html パーサーをプログラミングしています。最初に html ページがダウンロードされるため、後で分析できます。System.IO Exception をスローする Async Downloader を使用していますが、理解できません。
public void downloadFile(String address)
{
string pfad = @"c:\Greyhound";
if(!Directory.Exists(pfad))
{
Directory.CreateDirectory(pfad);
}
WebClient down = new WebClient();
down.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
down.DownloadFileAsync(new Uri(address), @"c:\Greyhound\page.html");
}
private void ProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
MainWindow mainwindow = new MainWindow();
mainwindow.UpdateProgress(e.ProgressPercentage);
}
MainWindows.cs
private void GoButton_Click(object sender, EventArgs e)
{
Downloader down = new Downloader();
down.downloadFile(Convert.ToString(AddressBox.Text));
}
public void UpdateProgress(int percentage)
{
progressBar.Value = percentage;
}
[Go] をクリックすると、フォルダが作成され、ダウンロードが開始されて終了します。私はそれをチェックしました。ファイルが存在し、適切なコンテンツで問題ありません。しかし、プログレスバーの上にマウスを移動すると、待機中の円が表示されます。デバッガーは、ここで IO 例外をスローすることを教えてくれます。
down.DownloadFileAsync(new Uri(address), @"c:\Greyhound\page.html");
「指定されたレジストリ キーは存在しません」と表示されますが、パスは間違っていません。ちなみに「 http://de.selfhtml.org/html/text/anzeige/h1_6.htm 」をダウンロードしています。