Some of my users would like to be able to unlock other users items. This is impossible unless you are an administrator. So I created a new button for the users. This is how it’s done.
First you have to place the button in Sitecore. Open the core database and find the “Workflow” ribbon chunk:
/sitecore/content/Applications/Content Editor/Ribbons/Chunks/Workflow
Then create a new “Small Button“. Name the button anything you wish. Write a command name in the “Click” field, for example “mycommand:unlockitem“. Also, remember to apply a header, tooltip and an icon, and remember to translate the header and tooltip :-)
When clicking the button, Sitecore executes the “mycommand:unlockitem” command. The connection between the command and a C# dll is created in the /App_Config/commands.config XML file. You can either extend the commands.config file directly, or create your own .config file and place the file in the /App_Config/Include folder. Sitecore will automatically merge anything in the /App_Config/Include folder into it’s configurations:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/" xmlns:x="http://www.sitecore.net/xmlconfig/"> <sitecore> <commands> <command name="mycommand:unlockitem" type="PT.Locks.Commands.UnlockItem, PT.Locks" /> </commands> </sitecore> </configuration>
The unlock code is pretty simple. You inherit from the Sitecore.Shell.Framework.Commands.Command class. You need to overwrite 2 functions. Execute() contains the code that is executed when the button is clicked. QueryState() determines if the button should be active (or visible) at all.
using System;
using Sitecore;
using Sitecore.Data.Items;
using Sitecore.Diagnostics;
using Sitecore.Shell.Framework.Commands;
namespace PT.Locks.Commands
{
[Serializable]
public class UnlockItem : Command
{
/// <summary>
/// Executes the command in the specified context.
/// </summary>
/// <param name="context">The context.</param>
public override void Execute(CommandContext context)
{
Item item = context.Items[0];
if (item.Access.CanWriteLanguage() && item.Locking.IsLocked())
{
Log.Audit(this, "Check in: {0}", new[] {AuditFormatter.FormatItem(item)});
item.Editing.BeginEdit();
item.Locking.Unlock();
item.Editing.EndEdit();
Context.ClientPage.SendMessage(this, "item:checkedin");
}
}
/// <summary>
/// Queries the state of the command.
/// </summary>
/// <param name="context">The context.</param>
/// <returns>The state of the command.</returns>
public override CommandState QueryState(CommandContext context)
{
Item item = context.Items[0];
if (item.Access.CanWriteLanguage() && item.Locking.IsLocked() && !item.Locking.HasLock() && !Context.IsAdministrator)
return CommandState.Enabled;
return CommandState.Hidden;
}
}
}
This command hides the button if you are an administrator (admins have an unlock button already) or if the item is not locked (obviously), or if the item is locked by you (you also have an unlock button to unlock your own items).
You can also apply security to the button so only specific users can unlock other users items.

September 13, 2010 at 5:25 am
With Security, this button makes perfect sense: Obviously you would not want anybody in a large enterprise to start unlocking each others items.
Alternativly, you could make this a “request unlock” button, which ships an email to the owner.
November 3, 2010 at 11:37 am
[...] you need a command that is attahced to a button in the Sitecore shell. In this example I will even add my button as a [...]
December 20, 2010 at 1:14 pm
[...] you are creating your own command, or is using the shell somehow, you could also activate the uiDeleteItems pipeline. Activating the [...]
April 4, 2011 at 7:41 pm
Great post! The only catch is that the users have to be setup with local administration role for the site.