Scattered throughout the site I am working on there are lots of videos, I have created a custom block for adding these. As part of the media area of the site though I need to pull in all of the videos, I want to do this programatically rather than relying on the users to add them all to a ContentArea, is there a way of programatically getting all blocks of a particular type like you would do for pages?
If you had EPiServer Find I would recommend using that to find them, if you have to use the built in API I would try with IContentLoader's GetDescendant() method.
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
contentLoader.GetDescendents(new ContentReference(blockFolderId)).Select(pageReference => contentLoader.Get<BlockData>(pageReference)).Where(block => block is MyBlockType)
Note that depending on how many blocks you have this can be quite a heavy operation.
Hope this helps
You could use IContentModelUsage.ListContentOfContentType(ContentType contentType).
Forgot to mention that the component that implements the interface can be retrieved from IOC container.
Thank you very much for your response, On your comment Johan, is there a method to get the ContentType either by a Guid or Sytem.Type to pass to the ListContentOfContentType?
There is a method Load on IContentTypeRepository that takes a type as parameter and returns a ContentType