ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / AddItem Method
The Item to be added to the project
Example

In This Topic
    AddItem Method (Project)
    In This Topic
    Adds the item to the current project. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public bool AddItem( 
       IProjectItem item
    )
    Public Function AddItem( _
       ByVal item As IProjectItem _
    ) As Boolean

    Parameters

    item
    The Item to be added to the project

    Return Value

    Returns a bool indicating whether or not the item was added successfully.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Add Folder to Project as IProjectItem
    {
      // Add a folder connection to a project
    
      Item folderToAdd = ItemFactory.Instance.Create(@"C:\Data\Oregon\Counties\Streets");
      var project = Project.Current;
      bool wasAdded = await QueuedTask.Run(() => project.AddItem(folderToAdd as IProjectItem));
      // use wasAdded;
    }
    Add GDBProjectItem to Project as IProjectItem
    {
      // Add a file geodatabase or a SQLite or enterprise database connection to a project
      Item gdbToAdd = folderToAdd.GetItems().FirstOrDefault(folderItem => folderItem.Name.Equals("CountyData.gdb"));
      var project = Project.Current;
      var addedGeodatabase = await QueuedTask.Run(() => project.AddItem(gdbToAdd as IProjectItem));
      // use addedGeodatabase;
    }
    Importing Maps To Project
    {
      // Import a mxd
      Item mxdToImport = ItemFactory.Instance.Create(@"C:\Projects\RegionalSurvey\LatestResults.mxd");
      var project = Project.Current;
      var addedMxd = await QueuedTask.Run(() => project.AddItem(mxdToImport as IProjectItem));
    
      // Add map package
      Item mapPackageToAdd = ItemFactory.Instance.Create(@"c:\Data\Map.mpkx");
      var addedMapPackage = await QueuedTask.Run(() => project.AddItem(mapPackageToAdd as IProjectItem));
    
      // Add an exported Pro map
      Item proMapToAdd = ItemFactory.Instance.Create(@"C:\ExportedMaps\Election\Districts.mapx");
      var addedMapProjectItem = await QueuedTask.Run(() => project.AddItem(proMapToAdd as IProjectItem));
    }
    Change the Project's default gdb path
    {
      //Create a new GDB item and add it to the project
      if (ItemFactory.Instance.Create(newGDDItemPath) is not IProjectItem newGDBItem)
      {
        // could not create the item
        return;
      }
      var success = Project.Current.AddItem(newGDBItem);
      //make the newly added GDB item the default
      if (success)
      {
        Project.Current.SetDefaultGeoDatabasePath(newGDDItemPath);
      }
      //Now remove the old item
      if (Project.Current.GetItems<Item>().FirstOrDefault(i => i.Path == oldGDBItemPath) is not IProjectItem oldGDBItem)
      {
        // could not find the item
        return;
      }
      var removeSuccess = Project.Current.RemoveItem(oldGDBItem);
    }
    Add a folder connection item to the current project
    {
      //Adding a folder connection
    
      //Create the folder connection project item
      var item = ItemFactory.Instance.Create(folderPath) as IProjectItem;
    
      var folder = await QueuedTask.Run(() =>
        Project.Current.AddItem(item) ? item as FolderConnectionProjectItem : null);
    }
    Add a geodatabase item to the current project
    {
      //Adding a Geodatabase:
      await QueuedTask.Run(() =>
      {
        //Create the File GDB project item
        var item = ItemFactory.Instance.Create(gdbPath) as IProjectItem;
        var newlyAddedGDB = Project.Current.AddItem(item) ? item as GDBProjectItem : null;
      });
    }
    Create an IProjectItem from a layout template pagx file and add it to the project
    {
      var templateFileName = "Layout.pagx";
      // Get layout Template Path from the project's home folder and combine it with a file name
      var projectPath = CoreModule.CurrentProject.HomeFolderPath;
      var layoutTemplateFilePath = System.IO.Path.Combine(projectPath, templateFileName);
      // Create a new layout project item with the layout file path
      // Create an IProjectItem using a layout template pagx file
      IProjectItem pagx = ItemFactory.Instance.Create(layoutTemplateFilePath) as IProjectItem;
      // Add the IProjectItem to the current project
      var project = Project.Current;
      await QueuedTask.Run(() => project.AddItem(pagx));
    }
    Import a pagx into a project
    {
      //Create a layout project item from importing a pagx file
      var project = Project.Current;
      await QueuedTask.Run(() =>
      {
        IProjectItem pagx = ItemFactory.Instance.Create(
                                  @"C:\Temp\Layout.pagx") as IProjectItem;
        project.AddItem(pagx);
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also