CommandWindow.TextDocument Property

Gets the TextDocument for the window or pane.

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

TextDocument TextDocument { get; }

Property Value

Type: EnvDTE.TextDocument
A TextDocument object.

Attempting to modify the document through this property or a EditPoint object fails because the entire document's region is read-only. You can modify the document only through members in CommandWindow object.

public void CodeExample(DTE2 dte, AddIn addin)
        // Get a reference to a Command window.
        Window win = dte.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow);
        CommandWindow cmdWin = (CommandWindow)win.Object;
        // Add some text to the window.
        cmdWin.OutputString("This is a line of text in the CommandWindow TextDocument");
        // Return the contents of the TextDocument and display them.
        TextDocument txtDoc = cmdWin.TextDocument;
        TextSelection txtSel = txtDoc.Selection;
        TextRanges txtRanges = txtSel.TextRanges;
        // Show text in textdocument.
        foreach (TextRange txtRange in txtRanges)
        // Show the CommandWindow's parent object's caption property.
        MessageBox.Show("The Parent window's caption: " + cmdWin.Parent.Caption);
        // Show the application object containing the CommandWindow.
    catch(Exception ex)

Community Additions