ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / GetItems<T> Method
The ProjectItem type that is used to filter the complete list of project items
Example

In This Topic
    GetItems<T> Method (Project)
    In This Topic
    Gets a collection of a specific type of items within the project
    Syntax
    Public Function GetItems(Of T As Item)() As IEnumerable(Of T)
    public IEnumerable<T> GetItems<T>()
    where T: Item

    Type Parameters

    T
    The ProjectItem type that is used to filter the complete list of project items

    Return Value

    Remarks

    To return all the databases in the project, for example, provide the appropriate project item type. For example, see the GDBProjectItem class in the ArcGIS.Desktop.Catalog namespace.

    If a type is not provided, all items that have been added to the current project will be returned, including the maps, layouts, toolboxes, default geodatabase, the home folder connection, and so on. A folder connection is a project item; subfolders and files accessed using a folder connection are items but are not project items because they have not been added to a project.

    Example
    Get MapProjectItems
    {
      // not to be included in sample regions
      var projectFolderConnection = Project.Current.GetItems<FolderConnectionProjectItem>().First();
    
      // Get all the maps in a project
      IEnumerable<MapProjectItem> projectMaps = Project.Current.GetItems<MapProjectItem>();
    }
    Get FolderConnectionProjectItems
    {
      // Get all the folder connections in a project
      IEnumerable<FolderConnectionProjectItem> projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
      // use projectFolders;
    }
    Get ServerConnectionProjectItems
    {
      // Get all the server connections in a project
      IEnumerable<ServerConnectionProjectItem> projectServers = Project.Current.GetItems<ServerConnectionProjectItem>();
      // use projectServers;
    }
    Get LocatorConnectionProjectItems
    {
      // Get all the locator connections in a project
      IEnumerable<LocatorsConnectionProjectItem> projectLocators = Project.Current.GetItems<LocatorsConnectionProjectItem>();
      // use projectLocators;
    }
    Get Project Items by ProjectItem type
    {
      // Get all the items that can be accessed from a folder connection. The items immediately 
      // contained by a folder, that is, the folder's children, are returned including folders
      // and individual items that can be used in ArcGIS Pro. This method does not return all 
      // items contained by any sub-folder that can be accessed from the folder connection.
      FolderConnectionProjectItem folderConnection = Project.Current.GetItems<FolderConnectionProjectItem>()
                                                          .FirstOrDefault(folder => folder.Name.Equals("Data"));
      //Note: Needs QueuedTask to run
      IEnumerable<Item> folderContents = folderConnection.GetItems();
    }
    Get Folder Item Content from Project PortalItem
    {
      FolderConnectionProjectItem projectfolderConnection = Project.Current.GetItems<FolderConnectionProjectItem>().First();
      var folderConnectionContent = projectfolderConnection.GetItems();
      var folder = folderConnectionContent.FirstOrDefault(folderItem => folderItem.Name.Equals("Tourist Sites"));
      var folderContents = folder.GetItems();
      //use folderContents;
    }
    Get all project items
    {
      IEnumerable<Item> allProjectItems = Project.Current.GetItems<Item>();
      foreach (var pi in allProjectItems)
      {
        //Do Something 
      }
    }
    Get all MapProjectItems for a project
    {
      var project = Project.Current;
      IEnumerable<MapProjectItem> newMapItemsContainer = project.GetItems<MapProjectItem>();
      // Note: Needs QueuedTask to run
      foreach (var mp in newMapItemsContainer)
      {
        //Do Something with the map. For Example:
        Map myMap = mp.GetMap();
      }
    }
    Get a specific MapProjectItem
    {
      MapProjectItem mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap"));
      // Use mapProjItem;
    }
    Get all StyleProjectItems
    {
      IEnumerable<StyleProjectItem> newStyleItemsContainer = null;
      newStyleItemsContainer = Project.Current.GetItems<StyleProjectItem>();
      foreach (var styleItem in newStyleItemsContainer)
      {
        //Do Something with the style.
      }
    }
    Get a specific StyleProjectItem
    {
      var container = Project.Current.GetItems<StyleProjectItem>();
      // example: projectStyleName = "ArcGIS 3D";
      StyleProjectItem testStyle = container.FirstOrDefault(style => style.Name == projectStyleName);
      StyleItem cone = null;
      if (testStyle != null)
      {
        // example: symbolName = "Cone_Volume_3";
        cone = testStyle.LookupItem(StyleItemType.PointSymbol, symbolName);
      }
      // Use (testStyle, cone);
    }
    Get the Favorite StyleProjectItem
    {
      // Note: Needs QueuedTask to run
      var containerStyle = Project.Current.GetProjectItemContainer("Style");
      var fav_style_item = containerStyle.GetItems().OfType<StyleProjectItem>().First(item => item.TypeID == "personal_style");
    }
    Get all GDBProjectItems
    {
      IEnumerable<GDBProjectItem> newGDBItemsContainer = null;
      newGDBItemsContainer = Project.Current.GetItems<GDBProjectItem>();
      foreach (var GDBItem in newGDBItemsContainer)
      {
        //Do Something with the GDB.
      }
    }
    Get a specific GDBProjectItem
    {
      GDBProjectItem gdbProjItem = Project.Current.GetItems<GDBProjectItem>().FirstOrDefault(item => item.Name.Equals("myGDB"));
      // Use gdbProjItem;
    }
    Get all ServerConnectionProjectItems
    {
      IEnumerable<ServerConnectionProjectItem> newServerConnections = null;
      var project = Project.Current;
      newServerConnections = project.GetItems<ServerConnectionProjectItem>();
      foreach (var serverItem in newServerConnections)
      {
        //Do Something with the server connection.
      }
    }
    Get a specific ServerConnectionProjectItem
    {
      ServerConnectionProjectItem serverProjItem = Project.Current.GetItems<ServerConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myServer"));
      // Use serverProjItem;
    }
    Get all folder connections in a project
    {
      //Gets all the folder connections in the current project
      var projectFolders = Project.Current.GetItems<FolderConnectionProjectItem>();
      foreach (var FolderItem in projectFolders)
      {
        //Do Something with the Folder connection.
      }
    }
    Get a specific folder connection
    {
      FolderConnectionProjectItem folderProjItem = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(item => item.Name.Equals("myDataFolder"));
      // Use folderProjItem;
    }
    Gets a specific LayoutProjectItem
    {
      LayoutProjectItem layoutProjItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals("myLayout"));
      // Use layoutProjItem;
    }
    Get all layouts in a project
    {
      //Gets all the layouts in the current project
      IEnumerable<LayoutProjectItem> projectLayouts = Project.Current.GetItems<LayoutProjectItem>();
      foreach (var layoutItem in projectLayouts)
      {
        //Do Something with the layout
      }
    }
    Get a specific GeoprocessingProjectItem
    {
      //Gets a specific GeoprocessingProjectItem in the current project
      // example: "myToolbox" is the name of the GeoprocessingProjectItem
      GeoprocessingProjectItem gpProjItem = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(item => item.Name.Equals("myToolbox"));
      // Use gpProjItem;
    }
    Get all GeoprocessingProjectItems in a project
    {
      //Gets all the GeoprocessingProjectItem in the current project
      var GPItems = Project.Current.GetItems<GeoprocessingProjectItem>();
      foreach (var tbx in GPItems)
      {
        //Do Something with the toolbox
      }
    }
    Search project for a specific item
    {
      List<Item> _mxd = [];
      //Gets all the folder connections in the current project
      var allFoldersItem = Project.Current.GetItems<FolderConnectionProjectItem>();
      if (allFoldersItem != null)
      {
        //iterate through all the FolderConnectionProjectItems found
        foreach (var folderItem in allFoldersItem)
        {
          //Search for mxd files in that folder connection and add it to the List<T>
          //Note:ArcGIS Pro automatically creates and dynamically updates a searchable index as you build and work with projects. 
          //Items are indexed when they are added to a project.
          //The first time a folder or database is indexed, indexing may take a while if it contains a large number of items. 
          //While the index is being created, searches will not return any results.
          _mxd.AddRange(folderItem.GetItems());
        }
      }
    }
    Refresh the child item for a folder connection Item
    {
      var contentItem = Project.Current.GetItems<FolderConnectionProjectItem>().First();
      //Check if the MCT is required for Refresh()
      if (contentItem.IsMainThreadRequired)
      {
        // Note: Needs QueuedTask to run
        contentItem.Refresh();
      }
      else
      {
        //if item.IsMainThreadRequired returns false, any
        //thread can be used to invoke Refresh(), though
        //BackgroundTask is preferred.
        contentItem.Refresh();
    
        //Or, via BackgroundTask
        ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
          contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
      }
    }
    Select an item in the Catalog pane
    {
      //Get the catalog pane
      IProjectWindow projectWindow = Project.GetCatalogPane();
      //or get the active catalog view...
      //ArcGIS.Desktop.Core.IProjectWindow projectWindow = Project.GetActiveCatalogWindow();
    
      //eg Find a toolbox in the project
      string gpName = "Interacting with Maps.tbx";
      var toolbox = Project.Current.GetItems<GeoprocessingProjectItem>().FirstOrDefault(tbx => tbx.Name == gpName);
      //Select it under Toolboxes
      projectWindow.SelectItemAsync(toolbox, true, true, null);//null selects it in the first container - optionally await
                                                               //Note: Project.Current.GetProjectItemContainer("GP") would get toolbox container...
    
      //assume toolbox is also under Folders container. Select it under Folders instead of Toolboxes
      var foldersContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
      //We must specify the container because Folders comes second (after Toolboxes)
      projectWindow.SelectItemAsync(toolbox, true, true, foldersContainer);//optionally await
    
      //Find a map and select it
      var mapItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map");
      //Map only occurs under "Maps" so the container need not be specified
      projectWindow.SelectItemAsync(mapItem, true, false, null);
    }
    Get a Layout by name from the current project
    {
      LayoutProjectItem layoutItemByName = Project.Current.GetItems<LayoutProjectItem>()
        .FirstOrDefault((lpi) => lpi.Name == "MyLayout");
      //Note: Needs QueuedTask to run
      Layout layoutByName = layoutItemByName.GetLayout();
    }
    Reference layout project items and their associated layout
    {
      //Reference layout project items and their associated layout.
      //A layout project item is an item that appears in the Layouts
      //folder in the Catalog pane.
      //Reference all the layout project items
      IEnumerable<LayoutProjectItem> layoutProjectItems =
                           Project.Current.GetItems<LayoutProjectItem>();
    
      //Or reference a specific layout project item by name
      LayoutProjectItem specificLayoutItem = Project.Current.GetItems<LayoutProjectItem>()
                                 .FirstOrDefault(item => item.Name.Equals("MyLayoutItem"));
    }
    Delete a report
    {
      //Note: Call within QueuedTask.Run()
      //Reference a ReportProjectItem in a project by name
      ReportProjectItem reportItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
      if (reportItem != null)
        //Delete the report from the project
        Project.Current.RemoveItem(reportItem);
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also