I am trying to get a list of projects and folders under it. I am able to get the projects and project-items using:
DTE2 dte2;
dte2=(DTE2)System.Runtime.InteropServices.Marshal.
GetActiveObject("VisualStudio.DTE.10.0");
Projects projects = dte2.Solution.Projects;
Then, I am iterating through the project items and getting the "kind" of item. But it is showing only GUID. I need to know whether the item is a Folder. How do I do that?
Ref:
var item = projects.GetEnumerator();
while (item.MoveNext())
{
var project = item.Current as Project;
for(i=1;i<project.ProjectItems.Count;i++)
{
string itemType = project.ProjectItems.Item(i).Kind;
}
}
EDIT :
Currently, I am using a workaround:
string location = project.ProjectItems.Item(i).get_FileNames(1);
if (location.EndsWith(@"\"))
{
// It is a folder E.g C:\\Abc\\Xyz\\
}
You can use
ProjectKinds.vsProjectKindSolutionFolder
to see whether the Project is a Folder or not.e.g.
EDIT: As mentioned in my comment, I realised after posting that the above is for SolutionFolders which are a Project.Kind rather than a ProjectItem.Kind. Regarding the GUIDS, Microsoft say:
From http://support.microsoft.com/kb/555561. As I said in the comment, hopefully the GUID for a ProjectItem of Kind "Folder" is the same across the board. You just need to determine this GUID and hardcode it.
You could use
EnvDTE.Constants.vsProjectItemKindPhysicalFolder
to compare theProjectItem.Kind
property against.More constants can be found here: http://msdn.microsoft.com/library/vstudio/envdte.constants