Let Sitecore Validate Item Name!
Many times we forget to use the cool ItemUtil API of Sitecore and write our own code do some tasks. One of such tasks is validating Sitecore item name while creating item on the fly (programmatically). Sitecore’s ItemUtil class will validate item name by replacing invalid characters (if any) in supplied item name.
Use below line of code for the same and you are good to go. string validItemName = Sitecore.Data.Items.ItemUtil.ProposeValidItemName(itemName);
If your supplied itemName is “news@2017” then above line of code will take care of invalid characters and propose you valid item name by removing “@”. Thus, it will return you “news2017” as a valid item name.
Liked it? If you have such a small and sweet Sitecore tip to share with the community then come and share here by filling this form.
Stay tuned for everyday tip!