If somebody like the post and its helpful in your work then, add comments.

Wednesday, November 2, 2011

SharePoint 2010 : Programmatically Add a Term to The SharePoint 2010 Term Store.

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 term

1 comment: