Checking Locks

Checking Locks

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Configuration.Factory
  • Sitecore.Data.Database
  • Sitecore.Data.Items.Item
  • Sitecore.StringUtil

Checking Locks C# Web Control Code

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();

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

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 : for colon and ? for question mark and   for space
output.Write("{0}&#58;&#160;{1}", "Item", "<b>" + item.DisplayName + "</b>");
output.RenderEndTag(); //P

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Ul);
output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}&#63;&#160;{1}", "Is Locked", "<b>" + item.Locking.IsLocked() + "</b>");
output.RenderEndTag(); //Li

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}&#63;&#160;{1}", "Has Lock", "<b>" + item.Locking.HasLock() + "</b>");
output.RenderEndTag(); //Li

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}&#63;&#160;{1}", "Can Lock", "<b>" + item.Locking.CanLock() + "</b>");
output.RenderEndTag(); //Li

output.RenderBeginTag(System.Web.UI.HtmlTextWriterTag.Li);
output.Write("{0}&#63;&#160;{1}", "Can Unlock", "<b>" + item.Locking.CanUnlock() + "</b>");
output.RenderEndTag(); //Li

output.RenderEndTag(); //Ul
output.RenderEndTag(); //Div


Checking Locks C# Web Control Output

  • Is Locked? False
  • Has Lock? False
  • Can Lock? True
  • Can Unlock? True