ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Core Namespace / FavoritesManager Class / CanAddAsFavorite Method
The item to be checked to see if it's a favorite candidate.
Example

In This Topic
    CanAddAsFavorite Method
    In This Topic
    Gets whether the item can be added to the favorites collection.
    Syntax
    public bool CanAddAsFavorite( 
       Item item
    )
    Public Function CanAddAsFavorite( _
       ByVal item As Item _
    ) As Boolean

    Parameters

    item
    The item to be checked to see if it's a favorite candidate.

    Return Value

    True if the item can be made a favorite. False otherwise
    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);
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also