Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Items are null in Sitecore 6

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).

like image 696
lurscher Avatar asked Dec 07 '10 16:12

lurscher


2 Answers

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);
like image 78
Yan Sklyarenko Avatar answered Nov 09 '22 03:11

Yan Sklyarenko


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 !

like image 40
csuwannarat Avatar answered Nov 09 '22 02:11

csuwannarat