ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Core Namespace / FavoritesManager Class / GetFavorites Method
Example

In This Topic
    GetFavorites Method
    In This Topic
    Retrieves the set of favorites from the favorite collection.
    Syntax
    public IReadOnlyList<Favorite> GetFavorites()
    Public Function GetFavorites() As IReadOnlyList(Of Favorite)

    Return Value

    A readonly list of Favorite.
    Example
    Get the set of favorites and iterate
    var favorites = FavoritesManager.Current.GetFavorites();
    foreach (var favorite in favorites)
    {
      bool isAddedToAllProjects = favorite.IsAddedToAllNewProjects;
      // retrieve the underlying item of the favorite
      Item item = favorite.Item;
    
      // Item properties
      var itemType = item.TypeID;
      var path = item.Path;
    
      // if it's a folder item
      if (item is FolderConnectionProjectItem)
      {
      }
      // if it's a goedatabase item
      else if (item is GDBProjectItem)
      {
      }
      // else 
    }
    
    Remove All Favorites
    var favorites = FavoritesManager.Current.GetFavorites();
    foreach (var favorite in favorites)
      FavoritesManager.Current.RemoveFavorite(favorite.Item);
    
    FavoritesChangedEvent
    ArcGIS.Desktop.Core.Events.FavoritesChangedEvent.Subscribe((args) =>
    {
      // favorites have changed
      int count = FavoritesManager.Current.GetFavorites().Count;
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also