We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

ProjectItems Interface

Contains ProjectItem objects, each representing items in the project.

Namespace:  EnvDTE
Assembly:  EnvDTE (in EnvDTE.dll)

public interface ProjectItems : IEnumerable

The ProjectItems type exposes the following members.

Public propertyContainingProjectGets the project hosting the project item or items.
Public propertyCountGets a value indicating the number of objects in the collection.
Public propertyDTEGets the top-level extensibility object.
Public propertyKindGets an enumeration indicating the type of object.
Public propertyParentGets the immediate parent object of a ProjectItems collection.

Public methodAddFolderCreates a new folder in Solution Explorer.
Public methodAddFromDirectoryAdds one or more ProjectItem objects from a directory to the ProjectItems collection.
Public methodAddFromFileAdds a project item from a file that is installed in a project directory structure.
Public methodAddFromFileCopyCopies a source file and adds it to the project.
Public methodAddFromTemplateCreates a new project item from an existing item template file and adds it to the project.
Public methodGetEnumeratorReturns an enumeration for items in a collection.
Public methodItemReturns a ProjectItem object in a ProjectItems collection.

This collection consists of a hierarchical (nested) structure of cascading ProjectItems collections that represent items in each project.

Reference this collection using Solution.Item().ProjectItems.

' Before running, create a new project or open an existing project.
Sub ListProj()
   Dim proj As Project = DTE.ActiveSolutionProjects(0)
   Dim win As Window = _
   ListProjAux(proj.ProjectItems(), 0)
End Sub

Sub ListProjAux(ByVal projitems As ProjectItems, ByVal Level As Integer)
   Dim projitem As ProjectItem
   For Each projitem In projitems
      MsgBox("Project item: " & projitem.Name, Level)
      ' Recurse if the project item has sub-items...
      Dim projitems2 As ProjectItems
      projitems2 = projitem.ProjectItems
      Dim notsubcoll As Boolean = projitems2 Is Nothing
      If Not notsubcoll Then
         ListProjAux(projitems2, Level + 1)
      End If
End Sub