![](https://csdnimg.cn/release/download_crawler_static/5960355/bgb.jpg)
Sitecore CMS 6.4 and later Content API Cookbook
Sitecore® is a registered trademark. All other brand and product names are the property of their respective holders. The
contents of this document are the property of Sitecore. Copyright © 2001-2013 Sitecore. All rights reserved.
Page 11 of 62
3.1 How to Access an Item
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:
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
Sitecore does compare case when evaluating item paths.
3.1.1 How to Access System Items
You can use members of the Sitecore.ItemIDs class to access system items without hard-coding
paths.
For example, to access the /Sitecore/Media Library item in the Master database:
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item mediaRoot =
master.GetItem(Sitecore.ItemIDs.MediaLibraryRoot);
3.1.2 How to Access System Data Templates
You can use the Sitecore.TemplateIDs class to access system data templates.
For example, to
access the standard template in the Master database:
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.TemplateItem standard =
master.Templates[Sitecore.TemplateIDs.StandardTemplate];
3.1.3 How to Access the Context Item
In presentation and other components, processing often begins with the context item.
You can
access the context item using the Sitecore.Context.Item property. For example, to access the
context item:
Sitecore.Data.Items.Item contextItem = Sitecore.Context.Item.
For more information about the members of the Sitecore.ItemIDs class, see the Sitecore API
documentation at http://sdn.sitecore.net/Reference/Sitecore%206.aspx.
For more information about the members of the Sitecore.TemplateIDs class, see the Sitecore
API documentation at http://sdn.sitecore.net/Reference/Sitecore%206.aspx.
For more information about the standard template, see the Data Definition Reference manual at
http://sdn.sitecore.net/Reference/Sitecore%206/Data%20Definition%20Reference.aspx.
For more information about the context item, see the Presentation Component Reference manual at
http://sdn.sitecore.net/Reference/Sitecore%206/Presentation%20Component%20Reference.aspx.