6

I have a WebBrowser that loads inside a WPF window. I need to get the title of the web page loaded in the WebBrowser.

I get the document using

object doc = this._browser.Document; and I can see that it is an mshtml.MSHTMLDocument and I want to cast it as this type so that I can pull the title out, however I can't find this type in any .NET library.

Will I have to create the type myself or am I just looking in the wrong place/approaching this wrong way?

How can I pull the page title out of a System.Windows.Controls.WebBrowser Document?

Adam
  • 1,483
  • 4
  • 21
  • 50

1 Answers1

14

Either add reference to Microsoft.mshtml and then:

var title = (webBrowser.Document as mshtml.HTMLDocument).title;

or

dynamic doc = webBrowser.Document;
var title = doc.title;
dkozl
  • 32,814
  • 8
  • 87
  • 89
  • which specific .dll contains Microsoft.mshtml? – Adam Jan 30 '14 at 20:24
  • If I go to Add Reference it will be under Extensions -> Miscosoft.mshtml – dkozl Jan 30 '14 at 20:26
  • We must be using different versions of Visual Studio or different IDEs. I am using Visual Studio 2010 and I don't have Extensions as a tab under Add Reference. Out of curiosity, in what directory is it located on your computer? I am banging my head against my desk trying to find this one file on my system. Maybe I will get lucky and have the same path. – Adam Jan 30 '14 at 20:40
  • 1
    C:\Program Files (x86)\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\Common\Microsoft.mshtml.dll, also search for _Microsoft HTML Object Library_ as I suggested in one of my old answers [here](http://stackoverflow.com/questions/17618739/how-to-get-value-from-any-tag-in-web-browser-control-using-wpf/17619452#17619452) – dkozl Jan 30 '14 at 20:44
  • Found it. The file was mshtml.tlb – Adam Jan 30 '14 at 20:46