Lock Settings

Lock Settings

Sitecore Lock Settings

  • AutomaticLockOnSave - automatically lock items during the time that they are being saved
  • AutomaticUnlockOnSaved - automatically unlock items immediately after they have been saved
  • KeepLockAfterSaveForAdminUsers - keep a lock on an item after an admin user saves it in the Page Editor
  • RequireLockBeforeEditing - determines whether the user must lock an item before editing it
  • UnlockAfterCopy - determines whether a copied item is unlocked.  The original item remains locked.

Automatic Unlocking

  • A locked item can be automatically unlocked when it is saved
  • This can be used to minimize the number of times when an admin needs to get involved to allow a business user to edit an item locked by someone who forgot to unlock the item when they had completed their editing of it
  • However, it is less convenient for the business user since they will need to relock items after each save
  • The configuration section of this page shows the default settings
  • When the value of AutomaticUnLockOnSaved is set to true in the web.config file, then every item is automatically unlocked after saving
  • When the value of AutomaticLockOnSave is set to true, then Sitecore automatically initiates a lock on an item when the item is saved

Unlocking Saved Items

  • Set AutomaticUnLockOnSaved to "true"
  • Set AutomaticLockOnSave to "false"

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Settings
  • Sitecore.Context
  • Sitecore.Data.Items.Item

Configuration Settings

<sitecore>
<configuration> 
    <settings>      
        <setting name="AutomaticLockOnSave" value="false" />
        <setting name="AutomaticUnlockOnSaved" value="false"/>
        <setting name="KeepLockAfterSaveForAdminUsers" value="false" />
        <setting name="RequireLockBeforeEditing" value="true" />
        <setting name="UnlockAfterCopy" value="true" />
    </settings>

C# Web Control Code

Sitecore.Data.Items.Item item = Sitecore.Context.Item;
if (item == null) return;

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.Write("C# Web Control Real-time Output");
output.RenderEndTag();

output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-size:x-small; width:100%; clear:both");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Div);
output.AddAttribute(System.Web.UI.HtmlTextWriterAttribute.Style, "font-weight:bold");
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.P);
//using &#58; for colon and &#160; for space
output.Write("{0}&#58;&#160;{1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

string autoLockOnSave = Sitecore.Configuration.Settings.AutomaticLockOnSave.ToString();
string autoUnlockOnSaved = Sitecore.Configuration.Settings.AutomaticUnlockOnSaved.ToString();
string keepLockAfterSaveForAdmin = Sitecore.Configuration.Settings.KeepLockAfterSaveForAdminUsers.ToString();
string requireLockBeforeEditing = Sitecore.Configuration.Settings.RequireLockBeforeEditing.ToString();
string unlockAfterCopy = Sitecore.Configuration.Settings.UnlockAfterCopy.ToString();

output.Write("{0}&#58;&#160;{1}", "Automatic Lock On Save", "<b>" + autoLockOnSave + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Automatic Unlock On Saved", "<b>" + autoUnlockOnSaved + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Keep Lock After Save For Admin Users" + "<b>", keepLockAfterSaveForAdmin + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Require Lock Before Editing", "<b>" + requireLockBeforeEditing + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Unlock After Copy", "<b>" + unlockAfterCopy + "</b>");

output.RenderEndTag(); //Div

C# Web Control Real-time Output

Item: Lock Settings

Automatic Lock On Save: False
Automatic Unlock On Saved: False
Keep Lock After Save For Admin Users: False
Require Lock Before Editing: True
Unlock After Copy: True