Parameters
- item
- The item to add to the favorite collection. For example a folder connection or a toolbox.
Return Value
The favorite item. Null if the item cannot be added as a favorite.
You should always check CanAddAsFavorite before passing an item to this method.
{
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);
}
}
}
{
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);
}
}
Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)