Updating Items

Updating Items

This snippet uses an index to reference the item’s field
  • Accesses the raw value of the field
  • Returns an empty string if the field does not exist or the field value is null
  • Does not generate inline editing controls for the Page Editor
  • Useful for simple fieldtypes
  • Use a security disabler to allow changes and place in a using block to ensure cleanup occurs


C# Web Control Code

using (new Sitecore.SecurityModel.SecurityDisabler())

{

      using (new Sitecore.Data.Items.EditContext(item))

      {

             item["fieldname"] = "newvalue";

      }

}