8

Does anyone (please) know how to do this? I thought that there would be an easy way to achieve this but can't find anything about saving the contents of WebBrowser HTML.

dgwyer
  • 739
  • 8
  • 19

2 Answers2

24

You might try something like this:

(Assuming C# 4 and WPF 4)

dynamic doc = webBrowser.Document;
var htmlText = doc.documentElement.InnerHtml;

Works for me...

kmontgom
  • 1,419
  • 13
  • 18
-3

Yous should use HttpWebRequest and HttpWebResponse objects. Simple sample (found in web, tested, working):

HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(@"http://www.[pagename].com");
myWebRequest.Method = "GET";

HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream());

string myPageSource = string.Empty;
myPageSource = myWebSource.ReadToEnd();
myWebResponse.Close();
zgorawski
  • 2,597
  • 4
  • 30
  • 43
  • I don't think that's what I need as I am altering the HTML in the WebBrowser control (adding new divs, form controls). I need to save the HTML directly from the control, not from a URL. – dgwyer Oct 12 '10 at 14:11