ArcGIS Pro 3.7 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 Function GetFavorites() As IReadOnlyList(Of Favorite)
    public IReadOnlyList<Favorite> GetFavorites()

    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 geodatabase 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
    {
      FavoritesChangedEvent.Subscribe((args) =>
      {
        // favorites have changed
        int count = FavoritesManager.Current.GetFavorites().Count;
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also