Partilhar via


ProjectItems.AddFromDirectory(String) Method

Definition

Adds one or more ProjectItem objects from a directory to the ProjectItems collection.

public:
 EnvDTE::ProjectItem ^ AddFromDirectory(System::String ^ Directory);
public:
 EnvDTE::ProjectItem ^ AddFromDirectory(Platform::String ^ Directory);
EnvDTE::ProjectItem AddFromDirectory(std::wstring const & Directory);
[System.Runtime.InteropServices.DispId(204)]
public EnvDTE.ProjectItem AddFromDirectory (string Directory);
[<System.Runtime.InteropServices.DispId(204)>]
abstract member AddFromDirectory : string -> EnvDTE.ProjectItem
Public Function AddFromDirectory (Directory As String) As ProjectItem

Parameters

Directory
String

Required. The directory from which to add the project item.

Returns

A ProjectItem object.

Attributes

Examples

This example works only in Visual Studio .NET 2003. For more information, see Migrating Code that Creates Projects by Using Templates.

Sub AddFromDirectoryExample()  
   ' This function creates a solution and adds a Visual Basic Console  
   ' project to it.   
   Dim soln As Solution  
   Dim proj As Project  
   Dim projitems As ProjectItems  

   ' Create a reference to the solution.  
   soln = DTE.Solution  

   ' Create a new solution.  
   soln.Create("c:\temp2", "MyNewSolution")  

   ' Create a new Visual Basic Console application project.  
   ' Adjust the save path as needed.  
   proj = soln.AddFromTemplate("C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\ConsoleApplication\Templates\1033\ConsoleApplication.vbproj", "c:\temp2", "My New Project", True)  
   projitems = proj.ProjectItems  

   ' Add all of the items in the specified directory (and subdirectories)   
   ' to the project.  
   projitems.AddFromDirectory("C:\Program Files\Microsoft Visual Studio .NET\Vb7\VBWizards\ConsoleApplication\Templates\1033")  
End Sub  

Remarks

AddFromDirectory steps through a given directory and its subdirectories, automatically adding all of its items to the project, saving you from having to do multiple add item operations.

Applies to