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

Posted on 2014-09-02
Last Modified: 2014-09-03
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
                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();
                // 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;
            catch (Exception objError)
                throw objError;
Question by:pothireddysunil
    LVL 74

    Accepted Solution

    What is this error means. If it is looking for the source code, how can i get it.
    An exception occurred within the HtmlAgilityPack (HAP) library. Basically, since you are running your code in debug mode within Visual Studio, VS is trying to display to you the actual source code that raised the error, but it cannot do that without the .pdb files that were generated when HAP was built. Since VS cannot find those files, it cannot display the source code, and thus displays the error that you have seen. There is nothing wrong with your code, per se; rather something has happened within HAP. I don't know that HAP distributes its .pdb files with the binaries. (It may.)

    How can i get the same source code for the HtmlAgilityPack which it was installed
    Most likely you will have to download the source code and build the library yourself. Then you will have the .pdb files that VS uses during debugging. The source code is available on CodePlex.


    You should be able to continue past the "no source code available" window by clicking "Cancel". Then you can see what the exception actually is. You may not be passing a parameter correctly or similar.
    LVL 1

    Author Comment

    Thanks Kaufmed. I tried, it's not giving me an option to cancel and move ahead with my debugging.
    LVL 1

    Author Comment

    It asks me to select the source code and once i selects it gives me this alert.

    Source file:
     Module: c:\users........\Debug\HtmlAgilityPacl.dll

     The source file is different from when the module was built. Would you like to use it anyway?

    It gives this alert for couple of ore classes and finally throws the below error.

    Source file information;

     Locating source for 'd:\Source\\Trunk\HtmlAgilityPack\HtmlDocument.PathMethods.cs'. Checksum: MD5 {21 f3 9f 31 c1 6a 76 67 a7 c1 d8 6f 9b b2 66 7d}
     The file 'd:\Source\\Trunk\HtmlAgilityPack\HtmlDocument.PathMethods.cs' does not exist.
     Looking in script documents for 'd:\Source\\Trunk\HtmlAgilityPack\HtmlDocument.PathMethods.cs'...
     Looking in the projects for 'd:\Source\\Trunk\HtmlAgilityPack\HtmlDocument.PathMethods.cs'.
     The file was not found in a project.
     Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\'...
     Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\crt\src\vccorlib\'...
     Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\mfc\'...
     Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\src\atl\'...
     Looking in directory 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\atlmfc\include'...
     Looking in directory 'C:\Users\sunil\Desktop\HtmlAgilityPack\Release\1_4_0\'...
     The debug source files settings for the active solution indicate that the debugger will not ask the user to find the file: d:\Source\\Trunk\HtmlAgilityPack\HtmlDocument.PathMethods.cs.
     The debugger could not locate the source file 'd:\Source\\Trunk\HtmlAgilityPack\HtmlDocument.PathMethods.cs'.

     If i selects NO - it asks me to select the source code again.

     I installed version
    LVL 1

    Author Comment

    Hi All, its resolved. its the input file path access issue. Thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now