Does HtmlAgilityPack have the ability to return the whole HTML markup from an HtmlDocument object as a string?
81
votes
Why do you need to return the whole markup as a string, when that's the input to something that parses it?
- Matt Ball
I am trying to save the markup directly to a word document ( .doc ) file.
- deostroll
Possible duplicate of HtmlAgility - Save parsing to a string
- Amit G
@MattBall because HTML Agility Pack isn't read only and it's not just for parsing! It allows you to make changes to the HTML elements. It's only natural that you would then want to be able to get the final HTML back out!
- BrainSlugs83
2 Answers
143
votes
-5
votes
You can create WebRequest passing Url and Get webResponse . Get ResponseStream from WebResponse and read it into a String.
string result = string.Empty;
WebRequest req = WebRequest.Create(Url);
WebResponse res= wrq.GetResponse();
StreamReader reader = new StreamReader(res.GetResponseStream());
result = reader.ReadToEnd();
reader.Close();
res.Close();
Hope this helps.