Get related pages?


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 but I want to do this in code so this way doesn't really help me.

Any advice is much appreciated

Jun 28, 2016 11:33

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

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:

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);

Edited, Jun 28, 2016 14:00

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.

Jun 28, 2016 15:14
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.