3

The return value of component.Id is TCM URI that contains the version information, such as tcm:00-00-v0.

However, I want to get the TCM URI of the Component in form of tcm:00-00.

How can I get the TCM URI of the Component without the version information?

I have code like this:

using System;
using System.Collections.Generic;
using Tridion.ContentManager.Extensibility;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Extensibility.Events;

namespace CreatePDFComponent
{
    [TcmExtension("CreatePDFComponent")]
    public class CreatePDFComponent : TcmExtension, IDisposable
    {
        private readonly List<EventSubscription> _subScriptions = new List<EventSubscription>();

        public CreatePDFComponent()
        {
            Subscribe();
        }

        private void Subscribe()
        {
            //when component is saved, event system (Create method) execute.
            EventSubscription subScription = EventSystem.SubscribeAsync<Component,
                                             SaveEventArgs>(Create, EventPhases.Processed);
            _subScriptions.Add(subScription);
        }

        // Create Images Component (Abbreviated)
        private void Create(Component component, SaveEventArgs args, EventPhases phases)
        {
            // component.Id is "tcm:00-00-v0" but I want to get "tcm:00-00"
            String componentId = component.Id.ToString().Replace("-v0", "");               
        }

        public void Dispose()
        {
            foreach (EventSubscription subscription in _subScriptions)
            {
                subscription.Unsubscribe();
            }
        }
    }
}
  • 4
    TcmUri componentId = component.Id.GetVersionlessUri(); – Nuno Linhares Oct 7 '13 at 14:05
  • You might want to consider subscribing to EventSystem.Subscribe<Component, CheckInEventArgs>(ComponentCheckInAction, EventPhases.TransactionCommitted) instead, this ensures it's fired when the Component is saved and checked in. Then you are sure to get a valid TCMURI, also on newly created items. – Bart Koopman Oct 7 '13 at 14:32
  • 1
    Nuno's comment is the answer. I don't know why it is a comment. – Jaime Santos Alcón Oct 7 '13 at 15:37
  • Because I said I wasn't answering anymore until you guys catch up to me :) – Nuno Linhares Oct 7 '13 at 16:24
  • Not sure it is possible to catch up the Nuno. Heck, in 2013 I'm still not where he was in back in 2008 when he did consulting work for us. – Glenn Stevens Oct 7 '13 at 19:30
5

I think you should provide more context in your question. Why you need the ComponentId if you already have access to the Component object?

Tridion will keep an editable version of your component during the whole edition process. This is the v0 you are observing. However you already have the component object and you can do operations with it.

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.