Share via


RunningDocumentTable Class

Provides access to the running document table (RDT) that tracks all currently opened documents in Visual Studio.

Inheritance Hierarchy

System.Object
  Microsoft.VisualStudio.Shell.RunningDocumentTable

Namespace:  Microsoft.VisualStudio.Shell
Assembly:  Microsoft.VisualStudio.Shell.10.0 (in Microsoft.VisualStudio.Shell.10.0.dll)

Syntax

'Declaration
Public Class RunningDocumentTable _
    Implements IEnumerable(Of RunningDocumentInfo), IEnumerable
public class RunningDocumentTable : IEnumerable<RunningDocumentInfo>, 
    IEnumerable
public ref class RunningDocumentTable : IEnumerable<RunningDocumentInfo>, 
    IEnumerable
type RunningDocumentTable =  
    class
        interface IEnumerable<RunningDocumentInfo>
        interface IEnumerable
    end
public class RunningDocumentTable implements IEnumerable<RunningDocumentInfo>, IEnumerable

The RunningDocumentTable type exposes the following members.

Constructors

  Name Description
Public method RunningDocumentTable Initializes a new instance of the RunningDocumentTable class.

Top

Methods

  Name Description
Public method Advise Enables the client to receive events about changes to the Running Document Table (RDT).
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method FindDocument(String) Gets an object from the Running Document Table (RDT) that represents the document specified by the given path.
Public method FindDocument(String, UInt32%) Gets a cookie from the Running Document Table (RDT) that represents the document specified by the given path.
Public method FindDocument(String, IVsHierarchy%, UInt32%, UInt32%) Gets an object, cookie, and owning project type from the Running Document Table (RDT) for the document specified by the given path.
Public method GetDocumentInfo Gets information about a document registered in the Running Document Table, given the identifier of the document.
Public method GetEnumerator Gets an enumerator of the documents in the Running Document Table.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetHierarchyItem Gets the project that owns the specified document.
Public method GetRunningDocumentContents(String) Uses the Running Document Table (RDT) to obtain the contents of a document given the path to the document.
Public method GetRunningDocumentContents(UInt32) Uses the Running Document Table (RDT) to obtain the contents of a document given the path to the document.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method LockDocument Gets a read or edit lock on the specified document.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method RegisterAndLockDocument Creates an entry in the running document table when a document is created or opened.
Public method RenameDocument Renames a document and optionally gives ownership of the document to the specified project.
Public method SaveFileIfDirty Saves the specified file if it has changed since the last save.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Unadvise Indicates the client is no longer interested in receiving Running Document Table (RDT) events.
Public method UnlockDocument Releases a read or edit lock on the open document.

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IEnumerable.GetEnumerator Enumerates the documents in the Running Document Table.

Top

Remarks

The running document table is used to track all documents that are currently opened in Visual Studio, whether they are visible or not. A VSPackage (see VSPackages) can access the RDT by calling the IServiceProvider.QueryService method on a service provider with the service ID of the SVsRunningDocumentTable service and the GUID of the IVsRunningDocumentTable interface.

This class simplifies access to the RDT for VSPackages by hiding the details of the IVsRunningDocumentTable interface behind a collection of useful methods. Note that the RunningDocumentTable class is used only for accessing document information. If you want to track RDT events, you must obtain the IVsRunningDocumentTable interface yourself (through the IServiceProvider.QueryService method on a service provider) and call the AdviseRunningDocTableEvents method with your own implementation of the IVsRunningDocTableEvents interface (or its derivatives).

The Source class uses this class to obtain the owning project of a document when building the list of error task items for the task windows.

Notes to Callers

Instantiate this class to obtain information about an open document. The resulting object is typically cached to enhance performance. Note that this class does not provide complete access to the RDT.

Examples

This example shows how to use this class from a language service to obtain the owning project of a file currently open in the editor.

using Microsoft.VisualStudio.Package;

namespace MyLanguagePackage
{
    public class MyLanguageService : LanguageService
    {
        IServiceProvider serviceProvider;

        public IVsHierarchy GetOwningProject(Source src)
        {
            RunningDocumentTable rdt = new RunningDocumentTable(this.serviceProvider);
            string filename = src.GetFilePath();
            return rdt.GetHierarchyItem(filename);
        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.VisualStudio.Shell Namespace