Names With Spaces

Names With Spaces

Controls featured in this example:

  • Sitecore Web Control

Classes featured in this example:

  • Sitecore.Data.Items.Item

Names With Spaces C# Web Control Code

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

Sitecore.Data.Items.Item home = Sitecore.Context.Database.GetItem("/sitecore/content/Home");
if (home == null) return;

Sitecore.Data.Items.Item[] descendants = home.Axes.GetDescendants();
if (descendants == 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);
output.Write("{0}: {1}", "Item", item.DisplayName);
output.RenderEndTag(); //P

int i = 0;
foreach (Sitecore.Data.Items.Item descendant in descendants)
{
if (System.Text.RegularExpressions.Regex.IsMatch(descendant.Name, @"\w+\s{1}\w+"))
{
i++;
output.Write("{0}", descendant.Paths.Path + "<br/>");
}
}
if (i == 0)
output.Write("{0}", "No pages currently contain a space in the item name");

output.RenderEndTag(); //Div


Names With Spaces C# Web Control Output

/sitecore/content/Home/Marketers/WebMarketing/WebForms/WFFM Forms
/sitecore/content/Home/SiteAdmins/IISAdministration/IISManagement/URL Rewrites
/sitecore/content/Home/Developers/ASPNET/ASPNETDevelopment/Regular Expressions
/sitecore/content/Home/Developers/ASPNET/SourceControl/Tortoise SVN
/sitecore/content/Home/Developers/CustomInterfaces/PageEditorUI/Page Editor Workflow
/sitecore/content/Home/Developers/ScriptingLanguages/JavaScript/JavaScript Basics
/sitecore/content/Home/SiteDirectory/Information/RSSFeeds/Marketing Feed
/sitecore/content/Home/SiteDirectory/Information/RSSFeeds/Test Feed
/sitecore/content/Home/SiteDirectory/Participation/Community/Thank you
/sitecore/content/Home/SiteDirectory/Participation/Community/Logout Confirmation