3

Is it possible to catch if an action is Publish or UnPublish in the SetPublishStateEventArgs?

I see in this post I can use the PublishOrUnPublishEventArgs.

Here is the code:

public MyEventSystem() 
{
    EventSystem.Subscribe<RepositoryLocalObject, SetPublishStateEventArgs>(GetPublishInfo, EventPhases.TransactionCommitted);
}

private void GetPublishInfo(RepositoryLocalObject subject, SetPublishStateEventArgs args, EventPhases phase)
{

    foreach (var item in args.ProcessedItems)
    {
        string title = subject.Title;
        string publicationTarget = args.Target.Title;
    }
}
0
5

I might be missing something in your question, but isn't it as simple as looking at args.IsPublished?

The SetPublishState event is only called after a successful transaction, so the Page will either be published or not after it. Which would result in:

  • args.IsPublished = true - Publish action

  • args.IsPublished = false - UnPublish action

2
  • But a page can be published (i.e. have a state of "published") after a succesful unpublish.
    – Dominic Cronin
    Jan 7 '15 at 9:48
  • @DominicCronin only for a different target, args.IsPublished belongs to args.Target here, which is not the same as the IsPublished icon on a Page in a list. Jan 7 '15 at 9:52

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.