Sometimes Sitecore will not return certain items. For instance, in the following code:
Sitecore.Data.ID itemId = new Sitecore.Data.ID(id);
Sitecore.Context.Database.GetItem(id);
This will return null, however if the same string id is placed on the search above the content tree in the content editor, it will return the item! The context database is web and I've republished the item several times.
I am using Sitecore 6.2.0 (rev. 100701).
Are you sure it is not a typo? I mean, shouldn't you pass itemId
instead of just id
to GetItem
?
I don't remember exactly how it works, but if you pass a string to this method, it probably treats it as path, not ID, and tries to resolve the item by path. You can check this much faster than I do:
Sitecore.Data.ID itemId = new Sitecore.Data.ID(id);
Sitecore.Context.Database.GetItem(itemId);
I just had the same issue - GetItem()
function returns NULL
After pulling my hair for about an hour, I found that my GetItem()
function is called by the front end and the extranet/Anonymous
user doesn't have read access to the item that I'm trying to get.
So, remember to check the security !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With