ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / Current Property
Example

In This Topic
    Current Property (Project)
    In This Topic
    Gets the project that is currently open in the ArcGIS Pro application
    Syntax
    public static Project Current {get;}
    Public Shared ReadOnly Property Current As Project
    Remarks

    Only one project can be opened at a time in ArcGIS Pro. When another project is opened or a new project is created, this property is updated to reflect the newly opened 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"));
      IEnumerable<Item> folderContents = await QueuedTask.Run(() => folderConnection.GetItems());
    }
    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;
    }
    Remove FolderConnection From Project
    {
      // Remove a folder connection from a project; the folder stored on the local disk
      // or the network is not deleted
    
      var project = Project.Current;
      await QueuedTask.Run(() =>
      {
        bool result = false;
        FolderConnectionProjectItem folderToRemove = project.GetItems<FolderConnectionProjectItem>()
          .FirstOrDefault(folder => folder.Name.Equals("Data"));
        if (folderToRemove != null)
        {
          result = project.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"));
      var project = Project.Current;
      var removedMapProjectItemResult = await QueuedTask.Run(() => project.RemoveItem(mapToRemove));
      // Use removedMapProjectItemResult
    }
    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));
    }
    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;
    }
    Add a Favorite - Style project item
    {
      StyleProjectItem styleItem = Project.Current.GetItems<StyleProjectItem>().
                              FirstOrDefault(style => style.Name == "ArcGIS 3D");
      if (FavoritesManager.Current.CanAddAsFavorite(styleItem))
      {
        // add to favorites with IsAddedToAllNewProjects set to false
        FavoritesManager.Current.AddFavorite(styleItem);
      }
    }
    Determine if the project is a portal project from a project's path
    {
      projectPath = Project.Current.Url;
      // A portal project path looks like this:
      //@"https://<ServerName>.<Domain>.com/portal/sharing/rest/content/items/1a434faebbe7424d9982f57d00223baa";
      //A local project path looks like this:
      //@"C:\Users\<UserName>\Documents\ArcGIS\Projects\MyProject\MyProject.aprx";
      bool isPortalProject = Uri.TryCreate(projectPath, UriKind.Absolute, out Uri uriResult)
                             && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
      if (isPortalProject)
      {
        System.Diagnostics.Debug.WriteLine("This is a portal project");
      }
      else
      {
        System.Diagnostics.Debug.WriteLine("This is not a portal project");
      }
      // Use isPortalProject;
    }
    Determine if the project is a portal project from a project object
    {
      var isPortalProject = Project.Current.IsPortalProject;
      // Use isPortalProject;
    }
    Get the portal from a portal project's path
    {
      projectPath = Project.Current.Url;
      // A portal project path looks like this:
      //@"https://<ServerName>.<Domain>.com/portal/sharing/rest/content/items/1a434faebbe7424d9982f57d00223baa";
      //A local project path looks like this:
      //@"C:\Users\<UserName>\Documents\ArcGIS\Projects\MyProject\MyProject.aprx";
    
      //Check if the project is a portal project
      bool isPortalProject = Uri.TryCreate(projectPath, UriKind.Absolute, out Uri uriResult)
                             && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);
      if (isPortalProject)
      {
        //Parse the project path to get the portal
        var uri = new Uri(projectPath);
        var fullUri = $"{uri.Scheme}://{uri.Host}/portal/";
        System.Diagnostics.Debug.WriteLine($"The Url of the project is: {fullUri}");
        //Now get the ArcGISPortal object from the portal Uri
        var arcgisPortal = ArcGISPortalManager.Current.GetPortal(new Uri(fullUri, UriKind.Absolute));
        System.Diagnostics.Debug.WriteLine($"The portal of the project is: {arcgisPortal.PortalUri}");
        //Note: You can set the active portal to be the portal of the project. Refer to this snippet: [ArcGISPortalManager: Get a portal and Sign In, Set it Active](ProSnippets-sharing#arcgisportalmanager-get-a-portal-and-sign-in-set-it-active)
      }
    }
    Get the Current project
    {
      //Gets the current project
      var project = Project.Current;
      // Use project
    }
    Get location of current project
    {
      //Gets the location of the current project; that is, the path to the current project file (*.aprx)
      projectPath = Project.Current.URI;
      // Use projectPath
    }
    Get the project's default gdb path
    {
      var projGDBPath = Project.Current.DefaultGeodatabasePath;
      // Use projGDBPath;
    }
    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);
    }
    Save project
    {
      //Saves the project
      var success = await Project.Current.SaveAsync();
    }
    Check if project needs to be saved
    {
      //The project's dirty state indicates changes made to the project have not yet been saved.
      bool isProjectDirty = Project.Current.IsDirty;
      // Use isProjectDirty;
    }
    SaveAs project
    {
      //Saves a copy of the current project file (*.aprx) to the specified location with the specified file name,
      //then opens the new project file
      var success = await Project.Current.SaveAsAsync(newProjectPath);
    
    }
    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;
      });
    }
    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>();
      await QueuedTask.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
    {
      await QueuedTask.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;
    }
    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);
      }
    }
    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)
      {
        await QueuedTask.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 project containers - for use with SelectItemAsync
    {
      //Use Project.Current.ProjectItemContainers
      var folderContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "FolderConnection");
      var gdbContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "GDB");
      var mapContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "Map");
      var layoutContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "Layout");
      var toolboxContainer = Project.Current.ProjectItemContainers.First(c => c.Path == "GP");
      //etc.
    
      //or...use Project.Current.GetProjectItemContainer
    
      folderContainer = Project.Current.GetProjectItemContainer("FolderConnection");
      gdbContainer = Project.Current.GetProjectItemContainer("GDB");
      mapContainer = Project.Current.GetProjectItemContainer("Map");
      layoutContainer = Project.Current.GetProjectItemContainer("Layout");
      toolboxContainer = Project.Current.GetProjectItemContainer("GP");
      //etc.
    }
    ProjectItem: Get an Item or Find an Item
    {
      //GetItems searches project content
      var map = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map1");
      var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(m => m.Name == "Layout1");
      var folders = Project.Current.GetItems<FolderConnectionProjectItem>();
      var style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 3D");
    
      //Find item uses a catalog path. The path can be to a file or dataset
      var fcPath = @"C:\Pro\CommunitySampleData\Interacting with Maps\Interacting with Maps.gdb\Crimes";
      var pdfPath = @"C:\Temp\Layout1.pdf";
      var imgPath = @"C:\Temp\AddinDesktop16.png";
    
      var fc = Project.Current.FindItem(fcPath);
      var pdf = Project.Current.FindItem(pdfPath);
      var img = Project.Current.FindItem(imgPath);
    }
    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
      await projectWindow.SelectItemAsync(toolbox, true, true, null);//null selects it in the first container
                                                               //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)
      await projectWindow.SelectItemAsync(toolbox, true, true, foldersContainer);
    
      //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);
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also