Document Property

HtmlWindow.Document Property

Note: This property is new in the .NET Framework version 2.0.

Gets the HTML document contained within the window.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in

public HtmlDocument Document { get; }
/** @property */
public HtmlDocument get_Document ()

public function get Document () : HtmlDocument

Property Value

A valid instance of HtmlDocument, if a document is loaded. If this window contains a FRAMESET, or no document is currently loaded, it will return a null reference (Nothing in Visual Basic).

Typically, you will access the Document through the Document property of the WebBrowser control. Use this property when you need to access a document within a FRAME using the Frames collection.

The following code example inspects each document within a page containing frames and creates a table of all of the outgoing hyperlinks from each page for future inspection.

private void GetLinksFromFrames()
    Hashtable linksTable = new Hashtable();
    string frameUrl;

    if (!(webBrowser1.Document == null))
        HtmlWindow currentWindow = webBrowser1.Document.Window;
        if (currentWindow.Frames.Count > 0)
            foreach (HtmlWindow frame in currentWindow.Frames)
                frameUrl = frame.Url.ToString();
                Hashtable frameLinksHash = new Hashtable();

                linksTable.Add(frameUrl, frameLinksHash);
                foreach (HtmlElement hrefElement in frame.Document.Links)
                    frameLinksHash.Add(hrefElement.GetAttribute("HREF"), "Url");
            Hashtable docLinksHash = new Hashtable();
            linksTable.Add(webBrowser1.Document.Url.ToString(), docLinksHash);

            foreach (HtmlElement hrefElement in webBrowser1.Document.Links)
                docLinksHash.Add(hrefElement.GetAttribute("HREF"), "Url");

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

© 2016 Microsoft