Get item by ID in Sitecore 6.5
Asked Answered
T

3

7

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"]);
    }
}
Tinea answered 21/10, 2014 at 11:50 Comment(0)
J
16

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

Jonette answered 21/10, 2014 at 11:57 Comment(2)
intellisense does not showing Id. May be something wrong with just mine.Tinea
Intellisense shows GetItem(string path), but that can be string containing an ID or path. They should have named it pathOrId :)Jonette
E
3

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.

Edina answered 21/10, 2014 at 11:58 Comment(0)
H
3

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

Healing answered 21/10, 2014 at 11:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.