Computer Magic Logo
Content modification

Friday, November 20, 2015

Published by Aristotelis Pitaridis

In order to modify a content we use the Umbraco Content Service. We use the GetById member function which gets the id of the content that we want to get. We can use the SetValue member function in order to set the value of a property. Finally we use the SaveAndPublishWithStatus member function in order to save our content.

//  Get the Umbraco Content Service
var contentService = ApplicationContext.Current.Services.ContentService;

// Get the content using it's id
var MyContent = contentService.GetById(1078);

// Set the property values
MyContent.SetValue("CMUmbracoToolsLanguage", Output);

// Save and publish the content
contentService.SaveAndPublishWithStatus(MyContent);