ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Core Namespace / FavoritesManager Class / GetFavorite Method
The item to retrieve from the favorite collection.
Example

In This Topic
    GetFavorite Method
    In This Topic
    Gets the item from the favorite collection.
    Syntax
    public Favorite GetFavorite( 
       Item item
    )
    Public Function GetFavorite( _
       ByVal item As Item _
    ) As Favorite

    Parameters

    item
    The item to retrieve from the favorite collection.

    Return Value

    The favorite item or null if the item is not a part of the favorite collection.
    Example
    Add a Favorite - Folder
    var itemFolder = ItemFactory.Instance.Create(@"d:\data");
    
    // is the folder item already a favorite?
    var fav = FavoritesManager.Current.GetFavorite(itemFolder);
    if (fav == null)
    {
      if (FavoritesManager.Current.CanAddAsFavorite(itemFolder))
      {
        fav = FavoritesManager.Current.AddFavorite(itemFolder);
      }
    }
    
    Insert a Favorite - Geodatabase path
    string gdbPath = "@C:\\myDataFolder\\myData.gdb";
    
    var itemGDB = ItemFactory.Instance.Create(gdbPath);
    
    // is the item already a favorite?
    var fav = FavoritesManager.Current.GetFavorite(itemGDB);
    // no; add it with IsAddedToAllNewProjects set to true
    if (fav != null)
    {
      if (FavoritesManager.Current.CanAddAsFavorite(itemGDB))
        FavoritesManager.Current.InsertFavorite(itemGDB, 1, true);
    }
    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);
    }
    
    Toggle the flag IsAddedToAllNewProjects for a favorite
    var itemFolder = ItemFactory.Instance.Create(@"d:\data");
    
    // is the folder item already a favorite?
    var fav = FavoritesManager.Current.GetFavorite(itemFolder);
    if (fav != null)
    {
      if (fav.IsAddedToAllNewProjects)
        FavoritesManager.Current.ClearIsAddedToAllNewProjects(fav.Item);
      else
        FavoritesManager.Current.SetIsAddedToAllNewProjects(fav.Item);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also