Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 420
Saint Avatar asked Jul 06 '16 08:07

Saint


1 Answers

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);
like image 75
Marek Musielak Avatar answered Sep 23 '22 02:09

Marek Musielak