How to add a Term to Term Store Object model SharePoint 2010

The new metadata features in 2010 are of great value to us. With each of our assets having a unique accounting identifier and our document contributors having room for improvement with naming documents favorably for search it could be a life savor!

Add following reference to the solution

using System.Globalization;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Taxonomy;

To add term in the term store, add following code

SPSite site = new SPSite("http://newdemo2010");
TaxonomySession taxSession = new TaxonomySession(site);
TermStore termStore = taxSession.TermStores["Managed Metadata Service"];
Group storeGroup = termStore.Groups["BPTemplate"];
TermSet termSet = storeGroup.TermSets["Timecard"];
termSet.CreateTerm(pTerm, 1033); //It will term to the root term
Term propertyIdsTerm = termSet.Terms["TimeLog"];
propertyIdsTerm.CreateTerm(pTerm, CultureInfo.CurrentCulture.LCID); //This 
will add term to a termtermStore.CommitAll();


Post a Comment

Popular Posts