Try our conversational search powered by Generative AI!

Get ContentLinks for blocks referencing a given block


It turns out to be quite easy to find the list of pages referencing a block:

var referencingPageLinks = _contentSoftLinkRepository.Service.Load(blockLink, true)
.Where(link => link.SoftLinkType == ReferenceType.PageLinkReference && !ContentReference.IsNullOrEmpty(link.OwnerContentLink))
.Select(link => link.OwnerContentLink)

But how do I get the same list but for the blocks referencing the given block? There is no BlockLinkReference or similar in ReferenceType enum...

Edited, Feb 05, 2018 11:22

Try and use the IContentRepository:

var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var references = repository.GetReferencesToContent(blockLink, false);
Feb 05, 2018 16:28

Try not to use ServiceLocator..


Feb 05, 2018 22:57

Indeed! ServiceLocator.Current should always be avoided in favor of dependency injection. laughing

(It does makes for more complete and easier to read/understand code examples, which makes it hard to resist in the forum even if I never use it in real code. wink)

Feb 06, 2018 14:10
* 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.