Add reference of "Microsoft.SharePoint.Taxonomy" assembly to your project. Include namespace "Microsoft.SharePoint.Taxonomy". And use the code as listed below.
using (SPSite site = new SPSite("Site URL"))
{
TaxonomySession _TaxonomySession = new TaxonomySession(site);
//Get instance of the Term Store
TermStore _TermStore = _TaxonomySession.TermStores["My Term Store"];
//Now create a new Term Group
Group _Group = _TermStore.CreateGroup("My New Group");
//Create a new Term Set in the new Group
TermSet _TermSet = _Group.CreateTermSet("My New Termset");
//Add terms to the term set
Term _term1 = _TermSet.CreateTerm("First Term", 1033);
Term _term2 = _TermSet.CreateTerm("Second Term", 1033);
Term _term3 = _TermSet.CreateTerm("Third Term", 1033);
Term _term4 = _TermSet.CreateTerm("Last Term", 1033);
//commit changes
_TermStore.CommitAll();
}
No comments:
Post a Comment