Skip to content

Instantly share code, notes, and snippets.

@5up3rman
Created August 31, 2017 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5up3rman/d1fbd3443208d788cd0696ffab446be4 to your computer and use it in GitHub Desktop.
Save 5up3rman/d1fbd3443208d788cd0696ffab446be4 to your computer and use it in GitHub Desktop.
An old Item Renamer from 2011. Very flawed.
public class EnforceItemName
{
protected void OnItemSaved(object sender, EventArgs args)
{
var currentItem = Sitecore.Events.SitecoreEventArgs.GetItem(args, 0);
if (currentItem != null && currentItem.Name.Contains(" ") && (currentItem.Paths.IsContentItem || currentItem.Paths.IsMediaItem))
{
currentItem.Editing.BeginEdit();
string displayName = currentItem.DisplayName;
currentItem.Name = currentItem.Name.ToItemName().ToLower();
currentItem.Appearance.DisplayName = displayName;
currentItem.Editing.EndEdit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment