October 13, 2015

Get Dictionary Item value in Sitecore

Sitecore Dictionary item is very helpful  to maintain key-value pair information in Sitecore instance.Below function to get dictionary item value by item name. You just need to pass dictionary path and item name

public string GetDictionaryItem(<Pass here dictionary item name>)      
{      
    Sitecore.Data.
Database database = Sitecore.Configuration.Factory.GetDatabase(“master”);      
   
Item currentItem = database1.GetItem(String.Concat(<dictionary path>, (<Pass here dictionary item name>));      
   
string val = String.Empty;      
   
if (currentItem != null)      
    {      
        val = currentItem[
“Phrase”];      
       
return val;      
    }      
   
return
val;      
}

That’s It.
Enjoy Learning.

No comments:

Post a Comment