Adding content to an "Editable region" web part programmatically

In some cases it’s necessary to add particular content to the Editable region programmatically. Our API can handle this query. Please read further to see such example code which can be used in your custom scripts.
Basically, you will need to add content to editable region using EditableWebParts property of the PageInfo class. Then it's necessary to save DocumentContent value to particular node and call Update on that document's node. Please see following code for inspiration:

// Add content text to the editable region (EditableRegion is ID of appropriate Editable region within the template)
CMS.CMSHelper.CMSContext.CurrentPageInfo.EditableWebParts["EditableRegion"] = "<div>content</div>";

// Node ID
int nodeid = CMS.CMSHelper.CMSContext.CurrentDocument.NodeID;

// Tree node
CMS.TreeEngine.TreeNode node = null;

// Tree provider
UserInfo ui = UserInfoProvider.GetUserInfo("administrator");
CMS.TreeEngine.TreeProvider tree = new CMS.TreeEngine.TreeProvider(ui);

// Get Single node specified by its ID
node = tree.SelectSingleNode(nodeid);

// Set DocumentContent value
node.SetValue("DocumentContent", CMS.CMSHelper.CMSContext.CurrentPageInfo.DocumentContent);

// Update node


See also: Update document example in Developer’s Guide
Kentico CMS API

Applies to: Kentico CMS 5.x
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.