Reader Level:
Article

Taxonomy TermSets in SharePoint 2010

By Vijai Anand on Feb 24, 2011
This article is about the TermSet in SharePoint.


In this article we will be seeing about the TermSet in SharePoint.

In this article we will be seeing the following:

  • Create a new TermSet for a group
  • Get all the termsets for a particular group

Steps Involved:
  • Open visual studio 2010.
  • Create a new console application.
  • Add the following references.

    o Microsoft.SharePoint.dll
    o Microsoft.SharePoint.Taxonomy.dll
     
  • Add the following namespaces.

    o Using Microsoft.SharePoint;
    o Using Microsoft.Sharepoint.Taxonomy;

Create a new TermSet for a group:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
namespace EMM
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://serverName:10/"))
            {
                TaxonomySession taxonomySession = new TaxonomySession(site);
                TermStore termStore = taxonomySession.TermStores["MMS"];
                Group group = termStore.Groups["SharePoint Group"];
                TermSet termSet = group.CreateTermSet("Word Automation Term Set");
                termStore.CommitAll();
            }
        }
    }
}

taxonomy.gif

Get all the termsets of a particular group:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
namespace EMM
{
class Program
{
static void Main(string[] args)
{
using (SPSite site = new SPSite("http://serverName:10/"))
{
TaxonomySession taxonomySession =
new TaxonomySession(site);
TermStore termStore = taxonomySession.TermStores[
"MMS"];
Group group = termStore.Groups[
"SharePoint Group"];
TermSetCollection termSetCol = group.TermSets;
foreach (TermSet termSet in termSetCol)
{
Console.WriteLine(termSet.Name);
}
Console.ReadLine();
}
}
}
}

Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, SharePoint 2010, Silv... Read more

COMMENT USING