ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Core Namespace / Favorite Class / Item Property
Example

In This Topic
    Item Property (Favorite)
    In This Topic
    Gets the favorite Item.
    Syntax
    public Item Item {get;}
    Public ReadOnly Property Item As Item
    Example
    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);
        }
      }
    }
    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);
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also