locked
vs2017 add existing folder to project RRS feed

Answers

  • Hi markgoldin,

    >>vs2017 add existing folder to project, how to do it?

    If the folder is in the project, we could add existing folder to project via visual studio.

    1. click the button named Show All files in solution explorer.

    2. you could see the folder name in solution explorer. right click the folder -> Include In Project.

    like this:

    3. If the folder out of the project, please copy it into the project.

    If you want to add the folder via programmatically, please refer to the following code.

    TE2 dte;
    EnvDTE.Project project;
    dte = ...
    project = dte.Solution.Projects.Item(1);
    
    AddFolderAndFiles(project, "My Folder");
    private void CreateFiles(string folderFullName)
    {
      System.IO.File.AppendAllText(System.IO.Path.Combine(folderFullName, "dummy1.cs"), "using System;");
      System.IO.File.AppendAllText(System.IO.Path.Combine(folderFullName, "dummy2.cs"), "using System.Windows.Forms;");
    }
    
    private void AddFolderAndFiles(EnvDTE.Project project, string folderName)
    {
       EnvDTE.ProjectItem folder;
       string folderFullName;
       string[] fileFullNames;
    
       try
       {
          folder = project.ProjectItems.AddFolder(folderName);
    
          folderFullName = folder.FileNames[0];
    
          CreateFiles(folderFullName);
    
          fileFullNames = System.IO.Directory.GetFiles(folderFullName);
    
          foreach (string fileFullName in fileFullNames)
          {
             folder.ProjectItems.AddFromFile(fileFullName);
          }
       }
       catch (Exception ex)
       {
          System.Windows.Forms.MessageBox.Show(ex.ToString());
       }
    }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by markgoldin Tuesday, February 13, 2018 9:53 AM
    Tuesday, February 13, 2018 5:33 AM

All replies

  • Your question is very general or ambiguous.
    Please provide more detailed information, that will make it easier to help you.

    Ashidacchi

    Tuesday, February 13, 2018 4:06 AM
  • Hi markgoldin,

    >>vs2017 add existing folder to project, how to do it?

    If the folder is in the project, we could add existing folder to project via visual studio.

    1. click the button named Show All files in solution explorer.

    2. you could see the folder name in solution explorer. right click the folder -> Include In Project.

    like this:

    3. If the folder out of the project, please copy it into the project.

    If you want to add the folder via programmatically, please refer to the following code.

    TE2 dte;
    EnvDTE.Project project;
    dte = ...
    project = dte.Solution.Projects.Item(1);
    
    AddFolderAndFiles(project, "My Folder");
    private void CreateFiles(string folderFullName)
    {
      System.IO.File.AppendAllText(System.IO.Path.Combine(folderFullName, "dummy1.cs"), "using System;");
      System.IO.File.AppendAllText(System.IO.Path.Combine(folderFullName, "dummy2.cs"), "using System.Windows.Forms;");
    }
    
    private void AddFolderAndFiles(EnvDTE.Project project, string folderName)
    {
       EnvDTE.ProjectItem folder;
       string folderFullName;
       string[] fileFullNames;
    
       try
       {
          folder = project.ProjectItems.AddFolder(folderName);
    
          folderFullName = folder.FileNames[0];
    
          CreateFiles(folderFullName);
    
          fileFullNames = System.IO.Directory.GetFiles(folderFullName);
    
          foreach (string fileFullName in fileFullNames)
          {
             folder.ProjectItems.AddFromFile(fileFullName);
          }
       }
       catch (Exception ex)
       {
          System.Windows.Forms.MessageBox.Show(ex.ToString());
       }
    }

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by markgoldin Tuesday, February 13, 2018 9:53 AM
    Tuesday, February 13, 2018 5:33 AM