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();
}
}
}
}
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.