Sunday, January 25, 2015

Sitecore: How to create valid Item Name through programmatically in c#.



Sitecore: How to create valid Item Name through programmatically in c#.

If you’re creating a new Sitecore item programmatically in C#, the general approach is to take some piece of data from your original data point, e.g. an events title, and customize it after removing some special characters from title so your item name is valid in Sitecore. 

Let’s take the example of an Event’s title that contains “Siteore Event !!..;  ”.so the Most of the developers will remove out the invalid character’s they can think would cause issues in Sitecore.

But instead of using your own algorithms to filter out the string, sitecore provides one inbuilt functionality  called "ProposeValidItemName" function which take input as a string and return the valid item name, so by using this function we can get rid off from our own custom algorithms to create valid item name.

Below is the code snippet of using this function.


String eventTitle ="Event !!..";
String ItemName = Sitecore.Data.Items.ItemUtil.ProposeValidItemName(eventTitle);


Happy coding!!!!!