AI OnAI Off
What do you mean by related?
Do you want to get all content that has a reference to your page?
The contentRepository has a GetReferencesToContent method you could have a look at.
You can have a look here of how to use it https://blog.i4code.nl/referencing-content-gadget/
Basically you would want to hook into the Publishevent with an InitializationModule and run your code there :)
Here's how you can hook into the event: http://world.episerver.com/blogs/Janaka-Fernando/Dates/2015/4/adding-custom-logic-to-your-publishing-step/
[InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class InitializationModule : IInitializableModule { public void Initialize(InitializationEngine context) { var contentEvents = ServiceLocator.Current.GetInstance<IContentEvents>(); contentEvents.PublishingContent += contentEvents_PublishingContent; } public void Uninitialize(InitializationEngine context) { //Add uninitialization logic } void contentEvents_PublishingContent(object sender, EPiServer.ContentEventArgs e) { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var related = contentRepository.GetReferencesToContent(e.ContentLink, includeDecendents: false); } }
Yes GetReferencesToContent worked. Strange i wasn't able to find that solution by googling. I instead reflected EPiServer.UI.dll on an episerver 6 site and checked how it was done there.
While saving a page I want to check which pages are related to it similar to whats happening when you move a page to the recycle bin.
I found this tutorial on how to build a plugin in edit to do this https://gregwiechec.com/2015/06/displaying-related-content-in-edit-mode/ but I want to do this in code so this way doesn't really help me.
Any advice is much appreciated