Sitecore 5.0 API

EditContext Class

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

[Visual Basic]
Public Class EditContext
    Implements IDisposable
[C#]
public class EditContext : IDisposable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

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.

Example

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"; } } } }

Requirements

Namespace: Sitecore.Data.Items

Assembly: Sitecore.Kernel (in Sitecore.Kernel.dll)

See Also

EditContext Members | Sitecore.Data.Items Namespace