Retrieving PublicationTarget in Event System Tridion 2011 SP1 HR1

28 Mar

Recently a colleague of mine and I were posed with a scenario where we needed to get the PublicationTarget of a PublishTransaction that exists in the Publishing Queue.

We quickly realized that there are several ways one might approach this problem. Reaching out to the SDL internal community, we received the following from KñewKñow:

The current publication + the current target type should help you determine which Publication Target(s) that is/are used.
You would probably do something like this:

  • Get a list of Publication Targets
  • Loop through targets and find those that have both the current publication in the “Allowed Publications” and the current Target Type in the “Allowed target Types”

TargetType targetType = (TargetType)session.GetObject(“tcm:0-3-65538”);

Publication context = (Publication)session.GetObject(“tcm:0-28-1”);

PublicationTargetsFilter filter = new PublicationTargetsFilter(session);

List<PublicationTarget> publicationTargets = new List<PublicationTarget>();

foreach (XmlNode node in session.GetList(filter)) {

   PublicationTarget target = (PublicationTarget)session.GetObject(node.Attributes[“ID”].Value); 

   if (target.TargetTypes.Contains(targetType)){

        if (target.Publications.Contains(context)) publicationTargets.Add(target);



This enabled us to put together a possible solution that satisfied our needs for the short term. We decided to see if there were some other API’s that would expose for us an alternative solution for this issue and what we discovered is that we could access the PublicationTarget from the PublishContext while we are enumerating the PublishTransaction.

IEnumerable<PublishTransaction> iePubTransaction = PublishEngine.GetPublishTransactions(filter);

    foreach (PublishTransaction cPt in iePubTransaction) {

        IList<PublishContext> ilPc = cPt.PublishContexts;

       PublicationTarget pubTar = ilPc[0].PublicationTarget;



Dangerous with a Blog

9 Jan

Welcome to Here you will find my ramblings.