It would definitely help if you just read the API documentation, but here is some sample code that should give you an idea:
[TcmExtension("ExampleEventHandlerExtension")]
public class EventHandler : TcmExtension {
public EventHandler() {
EventSystem.Subscribe<Component, SaveEventArgs>(ComponentSaveAction, EventPhases.Processed);
}
public static void ComponentSaveAction(Component subject, SaveEventArgs args, EventPhases phases) {
// the TCMURI of the Publication from this item
TcmUri contextRepository = subject.ContextRepository.Id;
// the TCMURI of the Publication where this item was localized
TcmUri owningRepository = subject.OwningRepository.Id;
if (subject.IsLocalized) {
BluePrintChainFilter filter = new BluePrintChainFilter(subject.Session) {
Direction = BluePrintChainDirection.Up
};
// the TCMURI of the Publication where this item was created
owningRepository = new TcmUri(subject.GetBluePrintChain(filter).Last().Id.ContextRepositoryId, ItemType.Publication);
}
// build TcmUri of parent Component
// (note using ItemId of owningRepositiory as a PublicationId,
// since that is a Publication TcmUri)
TcmUri uri = new TcmUri(subject.Id.ItemId, subject.Id.ItemType, owningRepository.ItemId);
// load parent Component
Component parent = new Component(uri, subject.Session);
}
}
Note I didn't test any of this, it is just an example to give you an idea of what you can use, please read the API documentation for every method shown here to see if it indeed is what you require.
If you need the same info via the Core Service see my answer to How to get the owning publication of a component via the Core Service?How to get the owning publication of a component via the Core Service?
update
@Josh was right, it needs to be direction Up
and Last()
, so updated my code accordingly.