Search code examples
c#sitecorepublishsitecore8

Unpublish sitecore item programmatically


I know it's possible to publish item from code level with Sitecore.Publishing.PublishManager. I don't see there option to unpublish an item.

Is it possible in some way?


Solution

  • You need to set value of __Never publish field to 1 (which is how Sitecore stores true boolean value) and publish the item.

    Yes, it's publishing, but because value of __Never publish is set to true, Sitecore will remove the item from the web database.

    You can also set value of this field by using item.Publishing.NeverPublish property.

    Something like this should do the trick:

    item.Editing.BeginEdit();
    item.Publishing.NeverPublish = true;
    item.Editing.EndEdit();
    
    PublishManager.PublishItem(item, targets, item.Languages, false, false);