ArcGIS Pro 3.1 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");
    bool wasAdded = await QueuedTask.Run(() => Project.Current.AddItem(folderToAdd as IProjectItem));
    
    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 addedGeodatabase = await QueuedTask.Run(() => Project.Current.AddItem(gdbToAdd as IProjectItem));
    
    Importing Maps To Project
    /// Import a mxd
    Item mxdToImport = ItemFactory.Instance.Create(@"C:\Projects\RegionalSurvey\LatestResults.mxd");
    var addedMxd = await QueuedTask.Run(
                  () => Project.Current.AddItem(mxdToImport as IProjectItem));
    
    /// Add map package      
    Item mapPackageToAdd = ItemFactory.Instance.Create(@"c:\Data\Map.mpkx");
    var addedMapPackage = await QueuedTask.Run(
                  () => Project.Current.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.Current.AddItem(proMapToAdd as IProjectItem));
    
    Add a folder connection item to the current project
    //Adding a folder connection
    string folderPath = "@C:\\myDataFolder";
    var folder = await QueuedTask.Run(() =>
    {
      //Create the folder connection project item
      var item = ItemFactory.Instance.Create(folderPath) as IProjectItem;
      //If it is succesfully added to the project, return it otherwise null
      return Project.Current.AddItem(item) ? item as FolderConnectionProjectItem : null;
    });
    
    //Adding a Geodatabase:
    string gdbPath = "@C:\\myDataFolder\\myData.gdb";
    var newlyAddedGDB = await QueuedTask.Run(() =>
    {
      //Create the File GDB project item
      var item = ItemFactory.Instance.Create(gdbPath) as IProjectItem;
      //If it is succesfully added to the project, return it otherwise null
      return Project.Current.AddItem(item) ? item as GDBProjectItem : null;
    });
    
    Import a pagx into a project
    //Import a pagx into a project.
    
    //Create a layout project item from importing a pagx file
    await QueuedTask.Run(() =>
    {
      IProjectItem pagx = ItemFactory.Instance.Create(
                                @"C:\Temp\Layout.pagx") as IProjectItem;
      Project.Current.AddItem(pagx);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also