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?
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.
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