Reputation: 26943
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).
Upvotes: 5
Views: 2901
Reputation: 5
refer the following article. http://sdn.sitecore.net/Articles/API/Context%20and%20databases.aspx
on web.config the site name="website" node may be pointing to the wrong database. The database property should be "master" or "web".
Upvotes: 0
Reputation: 146
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 !
Upvotes: 5
Reputation: 32240
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);
Upvotes: 5