This documentation is archived and is not being maintained.

Window.Document Property

Gets the Document object associated with the item, if one exists.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

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

function get Document () : Document

Property Value

A Document object.

For tool windows, Document returns Nothing.

public void CodeExample(DTE2 dte, AddIn addin)
    {   // Before running, create a text file called 
        // "TextFile1.txt", include it in your solution,
        // and make it the active window
        Window win;
        Document doc;
        if (dte.Documents.Count > 0)
            doc = dte.Documents.Item("TextFile1.txt");
            win = doc.ActiveWindow;
            // Show the name of the project that contains this window and document.
            win.Activate(); // Activate the window
            // Show the name of the current ProjectItem in the window.
            // How many other windows are available?
            string w = "Windows:\n";
            foreach (Window wi in win.Collection)
                w = w + wi.Caption + "\n";
            // Determine that the document returned by the document 
            // property is the same as the document object 'doc'.
            if (win.Document.Equals(doc))
                MessageBox.Show("The documents match!");
            else MessageBox.Show("The documents do not match!");
            // Close the window.
    catch(Exception ex)