Consider the following code:
1 |
Item rootItem = master.GetItem(new ID(id), Language.Parse(language)); |
All pretty straight-forwards. It knowingly uses the master db as its only needed within the cms realm.
How about if the item in question in unpublishable? What then happens? You get null!!?? So, how to actually get the item?
1 2 3 4 |
bool disableFiltering = Sitecore.Context.Site.DisableFiltering; Sitecore.Context.Site.DisableFiltering = true; Item rootItem = master.GetItem(new ID(id), Language.Parse(language)); Sitecore.Context.Site.DisableFiltering = disableFiltering; |
If you wanted to expand the idea and make it a bit more reusable you could build a disposable switcher to apply the same changes.
Hopefully this helps as it had me stumped for a while!
Nice view on a disturbing issue.
While working on content it’s not possible to preview/page edit an unpublishable item. This could be a fine addon to allow preview on those items.
Is this issue specific to Sitecore 6? Can’t quite reproduce that issue in 7.2.
Looks like you can find additional information on StackOverflow on the switcher example.
http://stackoverflow.com/questions/16838825/sitecore-publishable-flag-makes-it-impossible-to-getitem-from-master-database
Good q, the tests I’ve run have been in Sitecore 6.6.
One observation on the Switcher approach in the stackoverflow article, it doesn’t restore the state to the original instead it assumes it’s always false.