I was able to resolve these issues in the following manners:
- Creation of folder directly inside a Solution-
public static void AddingNewFolderInSolution(EnvDTE.DTE dte) {
Solution2 sol = (Solution2)dte.Solution;
Project solFolder = sol.AddSolutionFolder("NewFolderAdded");
sol.SaveAs(sol.FileName);
}
- Creation of folder directly inside a Project-
public static void AddingNewFolderInProject(EnvDTE.DTE dte) {
Solution sol = dte.Solution;
Project proj = sol.Projects.Item(1);
proj.ProjectItems.AddFolder(proj.FileName, Constants.vsProjectItemKindPhysicalFolder);
proj.Save();
}
The addition into the project is done using proj.projectItems.AddFolder()
- Creation of folder inside a Folder-
public static void AddingNewFolderInProject(EnvDTE.DTE dte) {
string pathToFolderOrProject = @"C:\Route\To\Folder";
Solution sol = dte.Solution;
//Accessing the first project as an example-
Project proj = sol.Projects.Item(1);
foreach (ProjectItem projItem in proj.ProjectItems) {
if (string.Compare(projItem.Kind, Constants.vsProjectItemKindPhysicalFolder) == 0) {
projItem.ProjectItems.AddFolder(pathToFolderOrProject, Constants.vsProjectItemKindPhysicalFolder);
}
}
proj.Save();
}
The addition of a folder inside an existing folder is done using projItem.projectItems.AddFolder()
where the path is the path to the parent folder+Name of new folder to be created.