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
  •  | 
  •  

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?

有帮助吗?

解决方案 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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top