Get all the instances of a block type


I am having some problems with the block types and wondering if anyone 

have any solution for getting all the instances of a blocktype?



Nov 29, 2012 15:59
Doesn't Johans loading multiple instaces work?
IEnumerable<ContentReference> references = GetSomeReferences();
IEnumerable<IContent> items = Locate.ContentRepository().GetItems<IContent>(references, LanguageSelector.AutoDetect());


Nov 29, 2012 16:27

Here is a code example if you mean looking for the content of certain type:

var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>();
var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>();

// loading a block type
var blockType = contentTypeRepository.Load<YourBlockType>();

// getting the list of block type usages, each usage object has properties ContentLink, LanguageBranch and Name
var usages = contentModelUsage.ListContentOfContentType(blockType);

// TODO: do the stuff with usages


Nov 30, 2012 9:27

Thank for the answers!

This will get me each usage of the created block, but i would like to get

a list of the available shared blocks no matter on which paghe the block is used.


For example, when im using contactblocks i would like to make a list of all 

published contactblocks and get the information from the blocks that i will then use 

to present on another page. Also, is it possible to somehow cast a contentusage to its actual blocktype

or do i have to get that content by using the contentreference ID from the contentusage object.


Thanks in advanced!

Nov 30, 2012 11:27

usage.ContentLink is the reference to block instance, so I guess this is what you need.

Nov 30, 2012 11:33

I will borrow this thread.

If I iterate on the usages in Dmytros example I thought I would get only the published instances of my block type. But it seems that I get all versions. 

In my case I populate a dropdown in an selectionfactory (I use the contentlink as value in my dropdown.). In another block where I use the dropdown I would like to choose the current version of a specific block instance for getting som data.

But now every time I publish my block containing the data I want to use I get another version in the dropdown. And to get the latest version in my "consuming" block I need to go into forms mode an choose the latest version which I don't want to do.

In my consuming block I want to choose among blocks of my blocktype by name and be able to always load the latest version.

How can I accomplish what I want.

Sep 18, 2013 13:29

I solved it. On the usage you can do like this ContentLink.CreateReferenceWithoutVersion() to get the correct reference.

Sep 18, 2013 14:37

Thanks Per. However


is obselete. Use this instead

Jun 20, 2017 17:59
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.