Get the parent URI of the BluePrinted component based on the URI of the child component

Does anyone know how I can find the URI of a parent component based on the URI for a generic or localized component in a child publish in SDL Tridion using Core Service?

+3


source to share


2 answers


Here is a simpler approach than the one suggested by Nuno and you don't need to reference any DLLs

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

      



GetTcmUri

the method is good for getting any TcmUris - just pass the post id where you want to point your item and the item id in the current post. So you can also find the id of a given element in a particular child publication

+5


source


You can use ComponentData.BluePrintInfo.OwningRepository.IdRef

TcmUri to retrieve the publication that "owns" this component. This is the first upstream publication where the component is either created or localized.

Then you can use something like this to get the Uri component in the correct 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 class TcmUri

is part of the Tridion.Common.dll file, which you can also link to your project.

+6


source







All Articles