Provides a mean to put an item in editing mode.
For a list of all members of this type, see EditContext Members.
System.Object
Sitecore.Data.Items.EditContext
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
To change the field values or name of an item, the item must be in editing mode. An item can enter editing mode by calling BeginEdit and leave using EndEdit. If the item is being edited without being in editing mode, an exception is raised. Changes to the items, is committed to the database when the editing mode is left.
The following examples updates news items in a news section with an old or yesterday marking. The two methods shows two different way of entering edit mode. public void UpdateNewsToOld(Item newsSection) { foreach(Item news in newsSection.Children) { if (news.TemplateName == "News") { news.BeginEdit(); try { news["Is Old"] = "1"; } finally { news.EndEdit(); } } } }
public void UpdateNewsToYesterday(Item newsSection) { foreach(Item news in newsSection.Children) { if (news.TemplateName == "News") { using(new EditContext(news)) { news["Yesterday"] = "1"; } } } }
Namespace: Sitecore.Data.Items
Assembly: Sitecore.Kernel (in Sitecore.Kernel.dll)
EditContext Members | Sitecore.Data.Items Namespace