开发者

Visual Studio Add-Ins: Can't get Document object from SelectedItems

Let me start by saying I'm new to developing add-ins for visual studio...

When using the DTE2 object, I am attempting to get some info on the document that is currently selected. If I do something like this:

DTE2 VisualStudioInstance = somethingOrOther;
Document documentInfo;

if(VisualStudioInstance.SelectedItems.MultiSelect == false)
{
    documentInfo = VisualStudioInstance.SelectedItems.Item(1).ProjectItem.Document;
}

The Document object always seems to be null. VisualStudioInstance.SelectedItems.Item(1).Project is also null (which I don't necessarily need, but that seems odd as well. It does give me the name of the selected item, so I know at least that it is finding something.

Now if I go directly to VisualStudioInstance.ActiveDocument, I get all the info I am looking for. Does the document actually have to be open to get the information? If so, how else would I go about getting d开发者_如何学Cocument info for a selected item without opening it? The main thing I'm looking for is full path information for the selected file. Thanks in advance.


Actually you can use ProjectItem.FileNames property. It is an indexed property which is valid even if the document is closed.


Open it first if it is closed, then the document instance should be available.

if (!projectItem.IsOpen)
{
    projectItem.Open();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜