Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

In Tridion event system, I have written the code to fire an OnPagePublishPost event. This task has been done successfully using the subscribe method i.e subscribing to the event.

But as my event code development, this event will be fired in two cases, while Publish button will be pressed or UnPublished button will be pressed. I need to write condition in code like

if (buttonPressed == publish)
{
    //do stuff publish
}
else if (buttonPressed == unpublish)
{
    //do stuff unpublish
}

How do I do this ?

share|improve this question

1 Answer 1

up vote 6 down vote accepted

It all depends to what event you actually subscribed, there are three parameters when you subscribe to an event, the subject type, event type and the phase. In your situation, the event type is crucial.

When you use the Tridion.ContentManager.Extensibility.Events.PublishOrUnPublishEventArgs, you will subscribe to both the Publish and UnPublish actions, details of which you should be able to find in the ContextVariables property of the EventArgs.

However, you can also subscribe separately to the Tridion.ContentManager.Extensibility.Events.PublishEventArgs and Tridion.ContentManager.Extensibility.Events.UnPublishEventArgs, these are probably the ones you are looking for, so you can separate your code even more cleanly. If you do require some code to be run on both the Publish and the UnPublish event and other code on either one of those separately, then you will want to debug your event system and check out what the property ContextVariables of your EventArgs contains.

As you will notice, the API Guide (requires login) is your friend here, just make sure you zoom in on the classes to see the full inheritance hierarchy.

share|improve this answer
    
You also have your guide summarizing the 2011 event system. sdltridionworld.com/articles/sdltridion2011/… –  Alvin Reyes Mar 8 at 6:30

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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