Adding Blocks into a content area programmatically

Vote:
 

hi, is there a way to add block on a content area programmatically?

 

#79508
Dec 19, 2013 4:29
Vote:
 

Yes. Here's some pseudo code

 

YourContentAreaProperty.Add(IContent);

Or if you already have a contentarea with references something like this.

YourPage.SetValue("ContentAreaPropertyName",contentareawithreferences).

Don't forget to save the page

contentRepository.Save(yourpageobject, EPiServer.DataAccess.SaveAction.Publish, Security.AccessLevel.NoAccess);

#79566
Dec 20, 2013 8:47
Vote:
 

This does not appear to work. After adding the block (IContent) it appears in the ContentArea, but after the save and reload the block disappears. It's also worth noting that it best to set where the saved block will be saved.

#87897
Jun 25, 2014 10:00
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.