How to programmatically add content to a Block List?

I am building an Umbraco 15 application.

  • The application contains a page of type Countries.
  • The page has a property called countryList, which is a Block List Editor.
  • It contains blocks with a DocumentType of Country.

I want to add new ‘countries’ to this Block List programatically (i.e. add new content to the Block List). How do I achieve this?

I currently retrieve a reference to the page and the property using the following code, but then I’m at a loss how to add content to the list.

CountryPage page = _umbracoHelper.Content(CountryPageId()) as CountryPage;
BlockListModel blockList = page.CountryList;

Can anyone point me in the right direction?


This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/115165-how-to-programmatically-add-content-to-a-block-list

Have you found a solution for this yet? I need to create it programmatically aswell and I cannot find any documentation for it for Umbraco 15+

Though not blockList.. there is a sample for blockGrid https://docs.umbraco.com/umbraco-cms/fundamentals/backoffice/property-editors/built-in-umbraco-property-editors/block-editor/block-grid-editor#creating-a-block-grid-programmatically

and quickBlocks package has some code you could lean on.. QuickBlocks/src/QuickBlocks/Services/BlockCreationService.cs at 112753bf5d25f9c00ad8660c81bb94c3561268b2 · prjseal/QuickBlocks · GitHub

ps lifted from this discussion ( Creating Blockgrid/Blocklist programmatically Umbraco #help-with-umbraco)