Retrieving the parent URI of a BluePrinted component based on the URI of a child component

StackOverflow https://stackoverflow.com/questions/14753025

  •  07-03-2022
  •  | 
  •  

Question

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?

Was it helpful?

Solution 2

Here's is simpler approach than the one that Nuno is proposing and you don't need to reference any dlls

var parentComponentid = ClientAdmin.GetTcmUri(component.Id, component.BluePrintInfo.OwningRepository.IdRef, null);

GetTcmUri method is good for getting any TcmUris - just pass publication id you want your item in and Id of item in current publication. This way you can also find ID of a given item in particular child publication

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top