Editing Mode

Editing Mode

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Context
  • Sitecore.Data.Items.Item

Editing Mode C# Web Control Code

Sitecore.Data.Database db = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item item = db.GetItem("/sitecore/content/home/developers/contentitems");
if (item == null) return;

using (new Sitecore.SecurityModel.SecurityDisabler())
{
if (item.Fields["TeaserAbstract"] != null)
{
item.Editing.BeginEdit();
try
{
item.Fields["TeaserAbstract"].Value = "Code examples for items";
Sitecore.Diagnostics.Log.Info("Teaser Abstract field updated", this);
}

catch (System.Exception ex)
{
item.Editing.CancelEdit();
Sitecore.Diagnostics.Log.Error("Teaser Abstract field update failed. " + ex.Message, this);
throw (ex);
}

item.Editing.EndEdit();
}

Notes

  • ASP.NET provides structured exception handling, which is used to logically organize error handling code concisely
  • Sitecore does not commit the changes if you call the Sitecore.Data.Items.Item.Editing.CancelEdit() method or do not call the Sitecore.Data.Items.Item.Editing.EndEdit() method
  • There is no real-time output for this code
  • This control is not bound to this page

Sources