Tuesday, February 26, 2013

Sharepoint add terms to metadata store using c#

Hi guys here you can find C# code to add terms to sharepoint metadata store.


private void setTagsToDirectory()
{
using (SPSite site = new SPSite("http://site-url"))
          {
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores["Managed Metadata Service"];
Group group = termStore.Groups["Test Terms"];
TermSet termSet = group.TermSets["Testing"];
try
{
Term keywordTerm;
keywordTerm = termSet.CreateTerm("apple", CultureInfo.CurrentCulture.LCID);
termStore.CommitAll();
}
catch (Exception)
{
//Term already exist in the current term set
}
}
}

This is how it looks in the metadata store after adding the term.



Feel free to give me feedback.
Thank You.

Luckshan Roy

No comments:

Post a Comment