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
If you need to get the Content Types, you can IContentRespository List() method.
To get actual instances of content, you can use IContentModelUsage ListContentOfContentType method. That will grab all the instances.
There is also a free app in Episerver's new App Marketplace that I think does something similar to the functionality you are seeking if you want to check it out.
edit: I see you tagged this with Episerver 8, and the app is only with 11 and above, so that may not work for you.