troubleshooting Question

How can I read an html page using HtmlAgilityPack in C#

Avatar of pothireddysunil
pothireddysunil asked on
C#Programming Languages-Other
4 Comments1 Solution2724 ViewsLast Modified:
I am trying to read an HTML page ( .htm page) , which is on my local drive using HtmlAgilityPack in C#.

Here are the things which i did.

1. Using Visual Studio 2012, first i installed HtmlAgilityPack using Package Manager Console -- NuGet.
2. It added HtmlAgilityPack  dll to my project.
3. Here is my code. I started running my code in debug mode, when it reached the below line
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
4. I got an error saying that
No Source available
There no source code available for the current location.

I am confused here. What source code it is looking for and Why it is looking for the source code as we already have the dll attached to the project

So, here are my questions on this issue

1. What is this error means. If it is looking for the source code, how can i get it.
2. How can i get the same source code for the HtmlAgilityPack which it was installed
3. how can I make it available to my application
4. how can i read the html tables

or is there any different approach that i can use to read the tables on the html page
          try
            {
                DirectoryInfo theFolder = new DirectoryInfo("\\\\MYPC\\Users\\Desktop");
                System.IO.FileInfo[] file = theFolder.GetFiles();
                int len = file.Length;
                if (file.Length > 1)
                {
                    int intLength;
                    fileName = Convert.ToString(file.GetValue(0));
                    intLength = fileName.IndexOf("_");
                }
                string FileName = "\\\\MYPC\\Users\\Desktop" + fileName;
                // Load the html document
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                doc.Load(FileName);
                // Get all tables in the document
                HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//TABLE");

               
                HtmlNodeCollection rows = tables(0).SelectNodes(".//TR");
                for (int i = 0; i < rows.Count; ++i)
                {
                   
                    HtmlNodeCollection cols = rows(i).SelectNodes(".//TD");
                    for (int j = 0; j < cols.Count; ++j)
                    {
                        // Get the value of the column and print it
                        string value = cols(j).InnerText;
                        Console.WriteLine(value);
                    }
                }
            }
            catch (Exception objError)
            {
                throw objError;
            }
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros