Find content with criteria?

Vote:
 

Hello

So, one would think there would be some way to search for blocks in the same way you search for pages using FindPagesWithCriteria, but I can't seem to find anything. Anyone have a clue or suggestion?

Thanks
Fredrik

#85809
May 06, 2014 10:15
Vote:
 

What do you want to find? 

You could use IContentModelUsage like below;

var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var repository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();
var myblockType = contentTypeRepository.Load<MyBlockType>();

List<ContentReference> myblockTypeReferences = contentModelUsage.ListContentOfContentType(myblockType).Select(x => x.ContentLink.ToReferenceWithoutVersion()).ToList();

then you could iterate through your references to get the data you need. 

foreach(ContentReference cref in myblockTypeReferences) {

MyBlockTypemyblock;
repository.TryGet<MyBlockType>(cref, out myblock);
}

or maybe IContentRepository.GetDescendents(ContentReference.BlockFolderToLookIn)

I'm don't think there is a way to search for blocks the same way as FindPagesWithCriteria

#86150
May 14, 2014 19:56