2

I started event system code for my project, where I am getting Target Types for a Publication. Please suggest how to get the Publication Targets based on the Target Type:

My Requirement is : I need to unpublish the component based on the Expiration Date (Metadata field) while publishing the component. I am using following event (PublishEventArgs).

EventSystem.Subscribe<Component, PublishEventArgs>(OnComponentPublishPost, EventPhases.TransactionCommitted);

I am following below snippet code

private void OnComponentPublishPost(Component component, PublishEventArgs args, EventPhases phase)
{
    foreach (PublishingTarget ty in args.Targets)
    {
       string targettype = ty.Id;
    }
}

Here I am getting Target type (ty.id). In unpublishing method I need to pass the Publication Target(targets).

PublishEngine.UnPublish(items, unpublishInstruction, targets);

Please suggest how to get the Publication Targets.

  • 1
    I think it will help if you edit your question and specify a bit more detail. Like what event are you subscribing to, and why you need the Publication Target? – Bart Koopman Apr 10 '17 at 14:03
  • One of the answers in this post has the snippet that might help you. – Guest19876 Apr 12 '17 at 7:34
  • What TCM version do you use? Starting from 8.1 there is an overload of UnPublish method that takes in target types. – AntonM Apr 14 '17 at 8:16

Your Answer

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

Browse other questions tagged or ask your own question.