2

How do I programmatically get an item on which I am performing publishing, irrespective of checkbox being checked (smart publish/ republish or publish related items or publish subitems)?

I don't want the whole publishing list just that item (the main item on which I clicked Publish->publish item). I have to make some code changes by modifying the publishing pipeline and not by event handler.

  • You find it.... in the publishing pipeline – Mark Cassidy Nov 11 '19 at 10:19
  • You can easily find this in Publishing Handler ...var rootItem = publisher.Options.RootItem; – Yogesh Sharma Nov 11 '19 at 11:04
5

In a publish pipeline processor, in order to get an item on which publishing is performed (the root item), you can use PublishContext and it's PublishOptions.RootItem property. The class should be inherited from Sitecore.Publishing.Pipelines.Publish.PublishProcessor.

Note: You can get RootItem when "Publish Item" operation is used, but the property will be null when "Publish Site" is triggered.

The following example shows how to get publishing RootItem in a publishing pipeline processor:

using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Publishing.Pipelines.Publish;

namespace CustomProcessors
{
    public class YourPublishProcessor : PublishProcessor
    {
        public override void Process(PublishContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            //this is the item on which "Publish item" operation was triggered
            Item rootItem = context.PublishOptions.RootItem;
        }
    }
}

You can also find a bit more information in this blog post. The RootItem will be available regardless of what publishing options are selected (smart publish/ republish or publish related items or publish subitems), but only available when "Publish Item" is triggered.

| improve this answer | |
  • It worked . Thanks Sergey :) – Niti Chauhan Nov 12 '19 at 11:48
  • I'm glad it worked, please click accept, if the answer was helpful.Thanks – Sergey Krivchenko Nov 12 '19 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.