Try our conversational search powered by Generative AI!

Get/Cast ContentArea from block property


I would like to query blocks to see if they have any content areas, and then loop through any items in the content areas.

At the moment I have a webform (its an MVC site - the webform is just for staging/dev environment) that lists all the pages on the site, as well as all the blocks within "MainContentArea", which is the primary ContentArea in my sites SitePageData. The page allows me at a glance to see where pagetypes and blocktypes have been used.

I would like to be able to interrogate the blocks that i find within the pages contentarea to see if they have any ContentAreas of their own, and then list the blocks therein. However i only seem to be able to get a list of the properties:

foreach(var y in blk.Property) {
    if("EPiServer.SpecializedProperties.PropertyContentArea" == y.GetOriginalType().ToString()) {

But i dont know how to get the actual ContentArea from the stated property.

Can anyone enlighten me?


Feb 10, 2017 14:20

The PropertyData has a property called Value which generally is an object so you need to cast it.

How about something like this? It's a short way to get your property values and check if they are ContentAreas

IEnumerable<BlockData> blocks = GetBlocks();

foreach (var block in blocks)
   var properties = block.Property;
   foreach (var key in properties.Keys)
      var contentArea = properties[key].Value as ContentArea;
      if(contentArea != null)
         var items = contentArea.Items; // Or use FilteredItems
         foreach (var item in items)
            var contentLink = item.ContentLink;
            // Get Content and start over. Preferably with some nested functionality

Though if you want to see references between content there are other ways.

Feb 10, 2017 15:00
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.