ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / RemoveItem Method
The IProjectItem to be removed
Example

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

    Parameters

    item
    The IProjectItem to be removed

    Return Value

    Returns a boolean indicating the operation's success.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    For items that are referenced by the project such as a folder, the folder connection is removed from the project but the folder continues to exist on the local disk or network. However, for items stored in the project such as maps and layouts, the map or layout definition is deleted when the project item is removed.
    Example
    Remove FolderConnection From Project
    {
      // Remove a folder connection from a project; the folder stored on the local disk 
      // or the network is not deleted
    
      //Note: Needs QueuedTask to run
      {
        bool result = false;
        FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>()
          .FirstOrDefault(folder => folder.Name.Equals("Data"));
        if (folderToRemove != null)
          result = Project.Current.RemoveItem(folderToRemove as IProjectItem);
        // use result
      }
    }
    Remove Map From Project
    {
      // Remove a map from a project; the map is deleted
      IProjectItem mapToRemove = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(map => map.Name.Equals("OldStreetRoutes"));
      // Note: Needs QueuedTask to run
      var removedMapProjectItemResult = Project.Current.RemoveItem(mapToRemove);
      // Use removedMapProjectItemResult
    }
    Remove a specific folder connection
    {
      // Remove a folder connection from a project; the folder stored on the local disk or the network is not deleted
      FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(myfolder => myfolder.Name.Equals("PlantSpecies"));
      if (folderToRemove != null)
        Project.Current.RemoveItem(folderToRemove as IProjectItem);
    }
    Remove a layout project item
    {
      //Remove a layout project item.
      //Remove the layout from the project
      //Note: Needs QueuedTask to run
      Project.Current.RemoveItem(layoutItem);
    }
    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);
    }
    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);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also