Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
HtmlDocument doc = new HtmlDocument(); doc.Load(yourhtml); doc.Save(Console.Out);
How to save this into an string instead of Console.Out
HtmlDocument
string s = doc.DocumentNode.OuterHtml;
or
var sw = new StringWriter(); doc.Save(sw); var s = sw.ToString();
Add a comment
how about
string html = doc.DocumentNode.OuterHtml;
OuterHTML will have the Entire HTML..
string s = doc.DocumentNode.OuterHtml
Why not using this:
var str = File.ReadAllText(yourHtml);
It will read your html document to string without initializing HtmlDocument object. Is yourHtmlreally a html or just a path? HtmlAgilityPack.HtmlDocument does not contain Load method accepting html.
yourHtml
string variableName = doc.DocumentNode.OuterHtml;
HtmlDocument doc = new HtmlDocument(); // call one of the doc.LoadXXX() functions Console.WriteLine(doc.DocumentNode.OuterHtml);
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
HtmlDocumentat all when you have the HTML in a string already?