views:

22

answers:

1

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.

A: 

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
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