I am trying to create custom report for Blocks list and usages int pages. So I need to get all list of block types available and the usages/links in pages.
I have tried the below code but this requires Block as input to fetch usages.
var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();
var myblockType = contentTypeRepository.Load<InputBlock>();
List<ContentReference> myblockTypeReferences = contentModelUsage.ListContentOfContentType(myblockType).Select(x => x.ContentLink.ToReferenceWithoutVersion()).Distinct().ToList();
InputBlock blockType;
foreach (ContentReference cref in myblockTypeReferences)
{
repository.TryGet<InputBlock>(cref, out blockType);
model.lstBlocks.Add(blockType);
}
I expect to not provide input block and get all list of block types available in Episerver and usages in pages
You would need to loop through all the content types and then loop through usages of all those content types. I used below function in Epi 11
Reference: EpiServer - How can I find out if a block is being used on any published page?