This documentation is archived and is not being maintained.

AddFromDirectory Method

Visual Studio .NET 2003

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

[Visual Basic .NET]
Public Function AddFromDirectory( _
   ByVal Directory As String _
) As ProjectItem
[Visual Basic 6]
Function AddFromDirectory( _
   ByVal Directory As String _
) As ProjectItem
HRESULT __stdcall AddFromDirectory(
   BSTR Directory,
   /* [out, retval] */ ProjectItem** retVal
ProjectItem AddFromDirectory(
   string Directory
[JScript .NET]
public function AddFromDirectory(
   Directory : String
) : ProjectItem


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

Return Value

Returns a ProjectItem object.


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.


The following example is designed to be run in Macros IDE.

Sub AddFromDirectoryExample()
   ' This function creates a solution and adds a Visual Basic .NET 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 VB 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

See Also

AddFromFile Method (ProjectItems Object) | AddFromTemplate Method (ProjectItems Object) | Open Method (General Extensibility)

Applies To: ProjectItems Collection