Try our conversational search powered by Generative AI!

Get ContentLinks for blocks referencing a given block

Vote:
 

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)
.ToList();

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

#187863
Edited, Feb 05, 2018 11:22
Vote:
 

Try and use the IContentRepository:

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

Try not to use ServiceLocator..

:trolling-emoji:

#187901
Feb 05, 2018 22:57
Vote:
 

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)

#187925
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.