ArcGIS Pro 3.2 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 bool RemoveItem( 
       IProjectItem item
    )
    Public Function RemoveItem( _
       ByVal item As IProjectItem _
    ) As Boolean

    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
    FolderConnectionProjectItem folderToRemove = Project.Current.GetItems<FolderConnectionProjectItem>().FirstOrDefault(folder => folder.Name.Equals("PlantSpecies"));
    if (folderToRemove != null)
      Project.Current.RemoveItem(folderToRemove as IProjectItem);
    
    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"));
    var removedMapProjectItem = await QueuedTask.Run(
             () => Project.Current.RemoveItem(mapToRemove));
    
    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);
    Delete_Layout
    //This example deletes a layout in a project after finding it by name.
    
    //Added references
    using ArcGIS.Desktop.Core; 
    using ArcGIS.Desktop.Layouts;
    
    public class DeleteLayoutExample
    {
      public static Task<bool> DeleteLayoutAsync(string LayoutName)
      {
        //Reference a layoutitem in a project by name
        LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
    
        //Check for layoutItem
        if (layoutItem == null)
          return Task.FromResult<bool>(false);
    
        //Delete the layout from the project
        return Task.FromResult<bool>(Project.Current.RemoveItem(layoutItem));
      }
    }
    Remove a layout project item
    //Remove a layout project item.
    
    //Remove the layout fro the project
    await QueuedTask.Run(() => Project.Current.RemoveItem(layoutItem));
    Delete a report
    //Note: Call within QueuedTask.Run()
    //Reference a reportitem in a project by name
    ReportProjectItem reportItem = Project.Current.GetItems<ReportProjectItem>().FirstOrDefault(item => item.Name.Equals(reportName));
    
    //Check for report item
    if (reportItem == null)
      return Task.FromResult<bool>(false);
    
    //Delete the report from the project
    return Task.FromResult<bool>(Project.Current.RemoveItem(reportItem));
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also