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