Errorhandling ?

Dec 6, 2009 at 8:29 AM

Hello anyone,

Iam a Newbi in C Sharp, but I using htmlagility for reading a Homepage for Links. Here my Example...

 

private void HtmlParser(string filePath)
    {    
    WebClient client = new WebClient();
    client.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648)");
    htmlDoc.OptionFixNestedTags=true;
    htmlDoc.Load(client.OpenRead(filePath));
       if (htmlDoc.ParseErrors!=null)
       {   
           ShowErrorDialog(filePath);
       }
       else
       {
            if (htmlDoc.DocumentNode != null)
            {
                foreach(HtmlNode link in htmlDoc.DocumentNode.SelectNodes("//a[@href]"))
                {
                HtmlAttribute att = link.Attributes["href"];
                if (att.Value.Substring)
                lstcontrol.Add(new GUIListItem(att.Value));
                }
            }
        }
    }

 

in Code "if (htmlDoc.ParseErrors!=null)" is ParseErrors always not null, but the Page is reading and the List contain all Links.

Why is that so ? Can I Display the Errormessage?

BigThx

Cyberbob