Documents

Document objects are used to represent an open document in the IDE. To contrast this abstraction with that provided by the Window object, a Window object is used to represent the physical UI aspects of a document window, whereas a Document object is used to represent the physical document that is being displayed within that document window.

A document could be a designer, such as the Windows Forms Designer, or it could be a text-based document such as a ReadMe file or a C# code file open in an editor.

Just as you get a list of all open windows using the DTE.Windows collection, you can use the DTE.Documents collection to retrieve a list of all open documents.

Dim documents As Documents = DTE.Documents

The Documents collection is indexed by the document’s Name property, which is, in effect, the document’s filename without the path information. This makes it easy to quickly retrieve a Document instance.

Dim documents As Documents = DTE.Documents

Dim readme As Document = documents.Item("ReadMe.txt")
Documents documents = DTE.Documents;
Document readme = documents.Item["ReadMe.txt"];

Using the Document object, you can do the following:

Image Close the document (and optionally save changes)

Image Retrieve the filename and path of the document

Image Determine whether the document has been modified since the last time it was saved

Image Determine what, if anything, is currently selected within the document

Image Obtain a ProjectItem instance representing the project item that is associated with the document

Image Read and edit the contents of text documents

Table 14.11 contains the member descriptions for the Document object.

Image
Image

TABLE 14.11 Document Members

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset