Sunday, February 17, 2008 8:41 AM
I went over the SolutionHierarchyTraversal in the DSK samples, where there is code there for going over all the files in the currently loaded Solution in the Solution Explorer window.
I saw that the GetProperty method over the hierarchy, with the property VSHPROPID_Name, does not return the full path name of the file. (e.g "C\Program Files\xx.txt", but only "xx.txt").
Is there a different property i should call to retrieve this information?
(I tried VSHPROPID_ProjectDir and got a "Not implemented" HResult).
10x a lot in advance,
Sunday, February 17, 2008 10:52 AMModeratorHi Michal,
I know that Gaston Milano does it in his add-in named Cool Commands for opening Windows Explorer in folder where project or project item is. I suspect he combines the VSHPROPID_Name of item with some path from its parent project.
Maybe it makes sense to contact him with your question.
Hope that helps,
Monday, February 18, 2008 2:03 PM
The code for the OpenProjectPath is really simple, I did it using automation.
Here is the code (without error checking) :Code Snippet
private void OnExploreProjectPath()
SelectedItems items = DTE.SelectedItems;
Selected item = items.Item(1);
if (item.Project != null)
ProjectItem pItem = item.ProjectItem;
If you have IVsHierarchy and you want a EnvDTE.Project you could use the following functionCode Snippet
public EnvDTE.Project ToDteProject(IVsHierarchy hierarchy)
object prjObject = null;
if (hierarchy.GetProperty(Oxfffffffe, -2007, out prjObject) >= 0)
return (EnvDTE.Project) prjObject;
throw new ArgumentException("Invalid hierarchy, the hierrarchy is not a project");
Hope this help.
Tuesday, July 15, 2008 9:05 PMThis doesn't appear to work for selected folders in a Visual C++ project, as the ProjectItem field is null.Any ideas on how to get the full path for the selected folder in solution explorer?
Wednesday, July 16, 2008 1:51 PMGot it.
Alternatively, this works:
1) Register an event handler with the DTE.Events.SelectionEvents.OnChange event.
2) In the event handler, obtain an IVsMonitorSelection interface (or keep one handy) and call GetCurrentSelection on it.
3) Cast the hierPtr to an IVsHierarchy: IVsHierarchy hier = Marshal.GetObjectForIUnknown(hierPtr) as IVsHierarchy;
4) Call IVsHierarchy.GetCanonicalName on this interface as shown in sample, using the ID obtained from the GetCurrentSelection.
- Edited by thethirdhalf Wednesday, July 16, 2008 2:11 PM Redundant line in code.