How to access Sitecore Items in Code Behind (Sitecore v6.5) – 4

To get a Sitecore Content Item, use Sitecore.Data.Database.GetItem(Path)

­Sitecore Content Item Class: Sitecore.Data.Items.Item 
(Get Sitecore Item from “/sitecore/content/Home/myItem”)
Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item myItem = master.GetItem("/sitecore/content/Home/myItem"); 
If item does not exist or current context user doesn’t have permission to access this item, Sitecore will return null or throw exception. 
Case is Insensitive while using path to get the items. 

To get a Sitecore Template Item, use Sitecore.Data.Database.GetTemplate(ID)
­Sitecore Template Item Class: Sitecore.Data.Items.TemplateItem 
(Get Template Item: Folder Template)
Sitecore.Data.Items.TemplateItem item = master.GetTemplate(Sitecore.TemplateIDs.Folder); 

To get a Sitecore Media Item, use Sitecore.Data.Database.GetItem(Path)
­Sitecore Media Item Class: Sitecore.Data.Items.MediaItem 
(Get Media Item from “/sitecore/content/Media Library/Images/Logo.png”)
Sitecore.Data.Items.Item myItem = master.GetItem("/sitecore/content/Media Library/Images/Logo.png");
 
To get a Sitecore System Item, use Sitecore.Data.Database.GetItem(ID)
­Sitecore Item Class: Sitecore.Data.Items.Item 
(Get System Item “Layouts”)
Sitecore.Data.Items.Item layoutsItem = master.GetItem(Sitecore.ItemIDs.Layouts);  

To get Sitecore Context Item, use Sitecore.Context.Item
­Sitecore Template Item Class: Sitecore.Data.Items.Item 
Sitecore.Data.Items.Item contextItem = Sitecore.Context.Item;

Note: Add Sitecore.Kernel.dll reference to project.



5 thoughts on “How to access Sitecore Items in Code Behind (Sitecore v6.5) – 4

  1. Hi,your blog is good for beginners those who want to know about sitecore.I am getting following error when i try to connect with sitecore 'master' database.The type 'System.Configuration.Provider.ProviderCollection' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

    Like

  2. Hi Nehem,I want that Sitecore users to see their own items in Workflow, want to restrict workbox to show only user specific item. Could you please provide any solution?

    Like

  3. Hi Nehemiah,I'm working on Web forms for marketers in sitecore 8.1. I created sample form inserted in a page and In Save Actions I added Send Email Message action to \”Submit\” button of the form. Modified parameter list of send email message action. When I preview form and fill form details,It is showing success message but not sending e-mail. Can you pls guide me through this.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website at WordPress.com
Get started
%d bloggers like this: