views:

51

answers:

1

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 document 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.

+1  A: 

Hi.

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

Vagaus
But how would I know which one is selected?
Ocelot20
Hi, I don't get it.VisualStudioInstance.SelectedItems.Item(1).ProjectItem should give you the current selected project item.From this, FileNames[1] should give you the full path to the file.The docs states that for some types (for instance resx) you may have multiple files but in my tests this didn't happen.best
Vagaus
My apologies, I thought you were talking about a standalone ProjectItem object and not one linked to the SelectedItems Item. I guess I should have actually checked before posting. Thanks for the help.
Ocelot20
Nothing to apologize :)
Vagaus