Skip to main content

Work with items as resources

Abstract

Describes the methods to check for overridden items and whether items are stored in the database or the resource file.

Sitecore provides methods to check for overridden items and to check if an item is stored in the database or the resource file.

To check if a resource item or list of items is overridden, you can use the Database.DataManager.DataSource.GetItemLocations(itemId).IsOverridden() method.

This method returns true if the item exists both in the database and in the resource file, otherwise false.

For example, to check if an item with itemId is overridden in the Master database:

var db = Database.GetDatabase(“master”);

bool isOverridden = db.DataManager.DataSource.GetItemLocations(itemId).IsOverridden();

For example, to check if a list of items is overridden in the Core database:

var db = Database.GetDatabase(“core”);

ICollection<AggregatedItemLocations>
locations = db.DataManager.DataSource.GetItemLocations(itemIds);

var overriddenItemIds = locations.Where(l=>l.IsOverridden());

To check if an item is stored in the database, you can use the Database.DataManager.DataSource.GetItemLocations(itemId).IsSql() method.

For example, to check if an item exists in the Master database:

var db = Database.GetDatabase(“master”);

bool isInDatabase = db.DataManager.DataSource.GetItemLocations(itemId).IsSql();

To check if an item is stored in the resource file, you can use the Database.DataManager.DataSource.GetItemLocations(itemId).IsResource() method.

For example, to check if an item exists in the Master resource file:

var db = Database.GetDatabase(“master”);

bool isResource = db.DataManager.DataSource.GetItemLocations(itemId).IsResource();

To get a list of all overridden items in the database, use the Database.DataManager.DataSource.GetOverriddenItems() method.

For example, to get a list of all the overridden items in the Master database:

var db = Database.GetDatabase(“master”);

var overriddenItemIds = db.DataManager.DataSource.GetOverriddenItems();