Getting root publication of component

亡梦爱人 提交于 2019-12-10 13:56:51

问题


Let’s assume the following publications for this question.

20 Content -> tcm:0-20-1

70 Web -> tcm:0-121-1

I’ve a component created under (20 Content) publication and I’m publishing this component from one of the child publications (70 Web). I’m using Dreamweaver template to write UI and I'm calling C# custom functions from DWT. While publishing, this component will be referred as 121-432 in component presentation. Is there any way to get the root publication of where the component is created? That’s I should get 20-432, instead of getting 121-432.

I’ve tried Component.GetBluePrintChain() and it returns a list that has all the blueprint hierarchy. I could get 1st item from this list to get this component with the publication where it is actually created.

Since I’ll have to call this method in many places, I just wanted to check if there any other direct/better way to get this done.

Can anyone suggest?


回答1:


You'll want to look at the OwningRepository property of the Component, so:

var componentIdInOwningPublication = new TcmUri(
    component.Id.ItemId,
    ItemType.Component,
    component.OwningRepository.Id.ItemId
);

Put that into a custom Dreamweaver-callable function and you should be good to go.

Update There also is a helper method called CreateTcmUriForPublication that does the translation. So you could also invoke that one like this:

var componentIdInOwningPublication = TemplateUtilities.CreateTcmUriForPublication(
    component.OwningRepository.Id.ItemId,
    component.Id
);

The end result of both snippets is the same though: the TcmUri of the Component in the context of its owning repository.



来源:https://stackoverflow.com/questions/13131273/getting-root-publication-of-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!