This project has moved. For the latest updates, please go here.

Create HTML Document Object from HTML Source code

Topics: Developer Forum
Feb 5, 2013 at 12:38 PM
Hi, i'm a bit of a newbie to HTML Agility Pack and I'm developing on a windows 8 machine using Visual Studio 2012 express.

I have a URL and I need to convert this HTML source code into a useable C# object. This object must be created at run time as the URL can change, is this an easy thing to do using this library? How can I go about it?

I've had a search round the internet to no prevail - it seems that the WebClient class does not exist within the new express addition. Is this right?
Feb 28, 2013 at 3:48 PM
Edited Feb 28, 2013 at 3:48 PM
Are you trying to just grab the entire HTML source of that URL and put into a string file?

If so,
HtmlWeb webfile = new HtmlWeb();

// load your the html source from the desired website into HtmlDocument file

HtmlDocument doc = webfile.Load("");

// since you want the entire HTML source as usable c# object, i.e. a string file
string websiteHTML = doc.DocumentNode.WriteTo();


You can print to console or to a text file to validate you got the source in its entirety (though I don't see why it wouldn't)

Hope that helps