dcsimg
 

Submitted by: Srinath M S(srinath_ms@yahoo.com)

Friday May 26th 2017 by Srinath M S

Language: .NET, Expertise: Intermediate - Explore how to copy the HTML document of the WebBrowser control in HTML format.

To copy the HTML document of the WebBrowser control in HTML format, you need to use the IHTMLDocument2 object of the MSHTML class.

For this, you need to add a reference to Microsoft.mshtml assembly which can be found in C:\Program Files\Microsoft.NET\Primary Interop Assemblies folder. Then write the following code in a button click event (btnCopyTextAsHTML in my example).

private void btnCopyTextAsHTML _Click(object sender, EventArgs e) 
{ 
   HtmlDocument document = myWebBrowser.Document; 
   if (document != null) 
   { 
     document.ExecCommand("SelectAll", false, null); 
     IHTMLDocument2 htmlDocument = document.DomDocument as IHTMLDocument2;      (htmlDocument.selection.createRange() as IHTMLTxtRange).execCommand("Copy", false, null); 
  } 
}
Home
Mobile Site | Full Site