We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

Document Interface

Represents a document in the environment open for editing.

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

public interface Document

The Document type exposes the following members.

Public propertyActiveWindowGets the currently active window, or the topmost window if no others are active. Returns Nothing if no windows are open.
Public propertyCollectionGets the collection containing the Document object.
Public propertyDTEGets the top-level extensibility object.
Public propertyExtenderReturns the requested Extender if it is available for this object.
Public propertyExtenderCATIDGets the Extender category ID (CATID) for the object.
Public propertyExtenderNamesGets a list of available Extenders for the object.
Public propertyFullNameGets the full path and name of the object's file.
Public propertyIndentSizeInfrastructure. Microsoft Internal Use Only.
Public propertyKindGets a GUID string indicating the kind or type of the object.
Public propertyLanguageInfrastructure. Microsoft Internal Use Only.
Public propertyNameGets the name of the Document.
Public propertyPathGets the path, without file name, for the directory containing the document.
Public propertyProjectItemGets the ProjectItem object associated with the Document object.
Public propertyReadOnlyInfrastructure. Microsoft Internal Use Only.
Public propertySavedReturns true if the object has not been modified since last being saved or opened.
Public propertySelectionGets an object representing the current selection on the Document.
Public propertyTabSizeInfrastructure. Microsoft Internal Use Only.
Public propertyTypeInfrastructure. Microsoft Internal Use Only.
Public propertyWindowsGets a Windows collection containing the windows that display in the object.

Public methodActivateMoves the focus to the current item.
Public methodClearBookmarksInfrastructure. Microsoft Internal Use Only.
Public methodCloseCloses the open document and optionally saves it, or closes and destroys the window.
Public methodMarkTextInfrastructure. Microsoft Internal Use Only.
Public methodNewWindowCreates a new window in which to view the document.
Public methodObjectReturns an interface or object that can be accessed at run time by name.
Public methodPrintOutInfrastructure. Microsoft Internal Use Only.
Public methodRedoRe-executes the last action that was undone by the Undo method or the user.
Public methodReplaceTextInfrastructure. Microsoft Internal Use Only.
Public methodSaveSaves the document.
Public methodUndoReverses the action last performed by the user in the document.

A Document object represents each open document or designer in the environment — that is, windows that are not tool windows and have an area to edit text. The Document object has members (properties, methods, and events) that you can use to manipulate the document. If it is a text file edited by the Visual Studio editor, then it also has a TextDocument object associated with it.

All open documents are referenced in the Documents collection. You can find a particular document by iterating through this collection.

The default property for a Document object is the Name property.

Reference this object by using DTE.Documents.Item(...).

Sub DocumentExample()
    Dim doc As Document
    Dim desc As String

    Set doc = DTE.ActiveDocument
    desc = "You are editing a "
    If (doc.ReadOnly) Then
        desc = desc & "read-only"
        desc = desc & "writable"
    End If
    desc = desc & " document called " & doc.Name & " located at " & doc.Path
    MsgBox desc
End Sub