Item Settings

Item Settings

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

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

Item Settings Configuration Setting

  • <configuration>
    • <sitecore>
      • <settings>
        • <setting name="MaxItemNameLength" value="100"/>

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

string defaultItem = Sitecore.Configuration.Settings.DefaultItem;
char[] invalidItemNameChars = Sitecore.Configuration.Settings.InvalidItemNameChars;
string itemNameValidation = Sitecore.Configuration.Settings.ItemNameValidation;
string maxItemNameLength = Sitecore.Configuration.Settings.MaxItemNameLength.ToString();
string invalidChars = string.Empty;

foreach (char invalidChar in invalidItemNameChars)
{
    invalidChars += invalidChar + "&#160;&#160;";
}

output.Write("{0}&#58;&#160;{1}", "Default Item", "<b>" + defaultItem + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Invalid Item Name Characters", "<b>" + invalidChars + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Item Name Validation", "<b>" + itemNameValidation + "</b><br/>");
output.Write("{0}&#58;&#160;{1}", "Maximum Item Name Length", "<b>" + maxItemNameLength + "</b>");
output.RenderEndTag(); //Div


Item Settings C# Web Control Output

Default Item: /home
Invalid Item Name Characters: \  /  :  ?  "  <  >  |  [  ]  
Item Name Validation: ^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$
Maximum Item Name Length: 100

Notes

  • The MaxNameLength setting identifies the maximum allowed number of characters and spaces for names of items in the Content Tree. The default is one hundred characters

Sources