Access an Item

Version: 10.4

You can use the Sitecore.Data.Items.Item class to access any item.

Note

Sitecore provides specialized classes to represent specific types as items, such as Sitecore.Data.Items.TemplateItem to represent a data template and Sitecore.Data.Items.MediaItem to represent a media item.

You can use the Sitecore.Data.Database.GetItem method to retrieve a Sitecore.Data.Item.Item. You can specify the ID of the item or the path to the item as the first parameter to the Sitecore.Data.Database.GetItem method. For example, to access the /Sitecore/Content/Home item in the Master database:

RequestResponse
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");

Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/home");

If the item does not exist, or the context user does not have read access rights to the item, the Sitecore.Data.Database.GetItem method returns null.

Note

We recommend that you keep the AllowDuplicateItemNamesOnSameLevel setting in the Sitecore.config set to false. If there are two items with the same pathname, Sitecore does not guarantee the resolving order to be one way or another.

You can also reference an item by using its ID value. For example, you can access a digital asset in the Sitecore Media Library:

RequestResponse
var siteItem = Sitecore.Context.Database.Items.GetItem("{FA952CEE-131E-438C-B3AE-1FD61CDC3C4D}");
Note

Sitecore does compare the case when evaluating item paths.

Do you have some feedback for us?

If you have suggestions for improving this article,