Does anyone know how can I find the URI of a parent Component based on the URI of a shared or localized component in a child publication in SDL Tridion using the Core Service?
You can use ComponentData.BluePrintInfo.OwningRepository.IdRef to get the TcmUri of the publication that "owns" that component. This is the first publication "going up" where the component is either created or localized.
Then you can use something like this to get you the component Uri in the right context:
internal string GetUriInBlueprintContext(string itemId, string publicationId)
{
if (TcmUri.UriNull == itemId)
return null;
TcmUri itemUri = new TcmUri(itemId);
TcmUri publicationUri = new TcmUri(publicationId);
TcmUri inContext = new TcmUri(itemUri.ItemId, itemUri.ItemType, publicationUri.ItemId);
return inContext.ToString();
}
The TcmUri class is part of the Tridion.Common.dll which you can reference from your project too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With