I am currently programming a html parser for a little research project. First the html page is downloaded, so it can be analyzed later on. I am using a Async Downloader which throws an System.IO Exception at me , which I don't understand.
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);
}
The 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;
}
When I click "Go" the Folder is created and the Download starts and finishes! I checked it. The File exists and is alright with the right content. But when I move the mouse over the progressbar the waiting circle appears. The Debugger tells me , that it throws a IO Exception here:
down.DownloadFileAsync(new Uri(address), @"c:\Greyhound\page.html");
And tells me: "Specified registry key does not exist" But the path is not wrong. I am downloading "http://de.selfhtml.org/html/text/anzeige/h1_6.htm" by the way.