Updating an existing EPiServer Composer function in code behind

by Fredrik Karlsson 25. March 2009 19:39

I recently posted some example code on how to create an EPiServer Composer page programatically so this is the natural follow up. Some very basic code on how to update an existing EPiServer Composer function programmatically.

// Get the extensionpage you want to update
ExtensionPageData subPage = ExtensionPageData.Load(CurrentPage.PageLink);
// Get the first content area on that page
ContentAreaData contentArea = subPage.GetContentAreas()[0];
// Get the first function on that page
// TODO: add some error handling / criterias when gettin tour desired function
ContentFunctionData block = contentArea.ContentFunctions[0];
// Get the episerver page that is the function
PageData functionPage = GetPage(block.ContentFunctionLink);
// Create a writable clone
PageData functionPageClone = functionPage.CreateWritableClone();
// Update a property
functionPageClone.Property["MainBody"].Value = new PropertyLongString("My long string");
// Save the function. make sure you use SaveAction.ForceCurrentVersion or you
// have to create a new version of the function aswell as the extensionpage
DataFactory.Instance.Save(functionPageClone, SaveAction.Publish | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess);

 

Tags: , ,

Development

blog comments powered by Disqus

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 Sweden License.


Welcome to the Dropit blog!

Here we, the people that work at Dropit, will write about stuff that interests us. For example web development, especially with .NET and EPiServer - but we'll also talk about other techniques that interest us, marketing on the web, social phenomenons, pop culture, games and software development in general.