GetItem on unpublishable Sitecore items

Consider the following code:

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?

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!

3 thoughts on “GetItem on unpublishable Sitecore items

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

Leave a Reply

Your email address will not be published. Required fields are marked *