Getting full name of file selected in Solution Explorer from Add-in

  • Thread starter Thread starter Johnny Jörgensen
  • Start date Start date
J

Johnny Jörgensen

In an add-in I'm doing, I need to get the full filename of the file(s)
selected by the Visual Studio 2005 user at a given time.

Using:

Dim win As Window = _applicationObject.ActiveWindow

Dim uih As UIHierarchy = Nothing

Dim uihItem As UIHierarchyItem = Nothing

If Not win Is Nothing Then

If win Is
_applicationObject.Windows.Item(Constants.vsWindowKindSolutionExplorer) Then

uih = CType(win.Object, UIHierarchy)

For Each uihItem In uih.SelectedItems

Dim itemName = uihItem.Name.ToString



Next uihItem

End If

End If

I can get the filename of the selected item, but I only get the filename,
not the full path, and there is no other properties on UIHierarchyItem that
seem to be of any help. Of course, I could recursively iterate the whole
solution tree looking fo the filename(s) found, but what if there is more
than one Form1.vb in the solution (in different projects of course)? Then I
wouldn't know which of them is the chosen item in the Solution Explorer
anyway.

UIHierarchyItem does have an "Object" property, but it doesn't look like I
can cast it to anything that can help my quest...

Cheers,

Johnny J.
 
Never mind - I solved the problem

You have to cast the "Object" to a ProjectItem - Not a Document item like I
first tried. Then it works like a charm

/Johnny
 
Back
Top