Export (0) Print
Expand All

ProjectItems Collection

Visual Studio .NET 2003

Contains ProjectItem objects, each representing items in the project.

DTE

   Projects

      Project

         ProjectItems

[Visual Basic .NET]
Public Interface ProjectItems
    Inherits IDispatch
[Visual Basic 6]
Class ProjectItems
[C++]
interface ProjectItems : IDispatch
[C#]
public interface ProjectItems : IDispatch
[JScript .NET]
public interface ProjectItems extends IDispatch

Remarks

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.

Note   In newer versions of Visual Studio .NET, special handling for the Project.ProjectItems collection for Visual C++ ® .NET is no longer required. That is, while the Visual C++ ® .NET ProjectItems collection previously stored all Visual C++ ® .NET project files in a flat list, now the files are stored hierarchically as they are in the other programming languages.
Since this change can affect your existing code, there is a way to emulate the old behavior in the new project-specific object model when trying to index the Project.ProjectItems collection to determine whether or not a file is in the project. The primary difference is that you can now return to the DTE object model by calling .Object on a Visual C++ ® .NET object.
Dim proj as VCProject = DTE.ActiveSolutionProjects(0).Object
Dim fileColl as IVCCollection = proj.Files
Dim file as VCFile = fileColl.Item("MyFile.cpp")
Dim projItem as ProjectItem = file.Object

Requirements

Namespace: EnvDTE

File: dte.tlb

Example

' Before running, create a new project or open an existing project.
Sub ListProj()
   Dim proj As Project = DTE.ActiveSolutionProjects(0)
   Dim win As Window = _
     DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
   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
   Next
End Sub

See Also

Project Object | Projects Collection | ProjectItem Object

Properties, Methods, and Events

Show:
© 2014 Microsoft