Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get item by ID in Sitecore 6.5

I am on Sitecore 6.5.

The below code is working fine but I don't understand how. The GetItem() method has six overload functions where it takes string values as just item paths.

In this case it's taking in an id as a string and correctly returning the item (the location is Sitecore droplink field). Am I missing something?

private Sitecore.Data.Items.Item LocationItem
{
    get
    {
        return Sitecore.Context.Database.GetItem(Item["Location"]);
    }
}
like image 346
Dheeraj Palagiri Avatar asked Oct 21 '14 11:10

Dheeraj Palagiri


People also ask

How to get items from Sitecore?

You can use the Sitecore. Data. Database. GetItem method to retrieve a Sitecore.

How do I find a Sitecore ID?

You can see the Item ID of any item by looking in the "Quick Info" section of the Content Editor main panel as illustrated...


3 Answers

The string parameter for GetItem() can be an ID or a Path.
Both will work.

like image 62
Ruud van Falier Avatar answered Oct 26 '22 23:10

Ruud van Falier


Sitecore can take a path or an ID as the string. Item["Location"] will contain a GUID (as the field type is a droplink), which you're currently retrieving as a string.

like image 45
Trayek Avatar answered Oct 26 '22 23:10

Trayek


This is expected functionality. You can pass both ID or path to this method, however documentation may not be clear on this.

like image 34
Martin Davies Avatar answered Oct 26 '22 23:10

Martin Davies