ArcGIS Pro 3.8 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
    {
      gdbPath = "@C:\\myDataFolder\\myData.gdb";
      var itemGDB = ItemFactory.Instance.Create(gdbPath);
    
      // is the item already a favorite?
      var favorite = FavoritesManager.Current.GetFavorite(itemGDB);
      // no; add it with IsAddedToAllNewProjects set to true
      if (favorite != null)
      {
        if (FavoritesManager.Current.CanAddAsFavorite(itemGDB))
        {
          FavoritesManager.Current.InsertFavorite(itemGDB, 1, true);
        }
      }
    }
    Toggle the flag IsAddedToAllNewProjects for a favorite
    {
      var newItemFolder = ItemFactory.Instance.Create(@"d:\data");
    
      // is the folder item already a favorite?
      var favorite = FavoritesManager.Current.GetFavorite(newItemFolder);
      if (favorite != null)
      {
        if (favorite.IsAddedToAllNewProjects)
        {
          FavoritesManager.Current.ClearIsAddedToAllNewProjects(favorite.Item);
        }
        else
        {
          FavoritesManager.Current.SetIsAddedToAllNewProjects(favorite.Item);
        }
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also