ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Core Namespace / FavoritesManager Class / InsertFavorite Method / InsertFavorite(Item,Int32,Boolean) Method
The item to add to the favorite collection. For example a folder connection or a toolbox.
The index at which the item is to be inserted.
Is the new favorite to be added to all new projects.
Example

In This Topic
    InsertFavorite(Item,Int32,Boolean) Method
    In This Topic
    Inserts an item to the favorites collection.
    Syntax
    public Favorite InsertFavorite( 
       Item item,
       int index,
       bool addToAllNewProjects
    )
    Public Overloads Function InsertFavorite( _
       ByVal item As Item, _
       ByVal index As Integer, _
       ByVal addToAllNewProjects As Boolean _
    ) As Favorite

    Parameters

    item
    The item to add to the favorite collection. For example a folder connection or a toolbox.
    index
    The index at which the item is to be inserted.
    addToAllNewProjects
    Is the new favorite to be added to all new projects.

    Return Value

    The favorite item. Null if the item cannot be added as a favorite.
    Remarks
    An item can only exist once in the favorite collection. If the item already exists in the favorites collection, then no additional item is inserted. However the existing item will be moved to the specified index and the Favorite.IsAddedToAllNewProjects property will be updated.

    You should always check CanAddAsFavorite before passing an item to this method.

    Example
    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);
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also