Saturday, 8 November 2014

Retrieving Sitecore items

Retrieving Sitecore items

All items are accessed through the Sitecore.Data.Items.Item class

You are mostly going to get an instance of an item through the Sitecore.Data.Database class. This allows you to retrieve items normally by specifying a path or an ID. Like this:

//Get the master database through a Factory
Database masterDb = Sitecore.Configuration.Factory.GetDatabase("master");
   
//Retrieving an item with a path through the database
Sitecore.Data.Items.Item myItem = masterDb.Items["/sitecore/content/home"];
  
//Retrieving an item from an item id

Sitecore.Data.Items.Item mySecondItem = masterDb.Items[newID("{BB07A18A-580D-4105-9A1D-F3072D1A0BE3}")];

No comments:

Post a Comment