Taxonomy groups in SharePoint 2010


In this article we will be seeing how to create a new taxonomy group for a term store in SharePoint 2010 using API.

In this article we will be seeing the following:

  • Create a new group in a term store
  • Get all the groups for a particular term store

Steps Involved:

  • Open visual studio 2010.
  • Create a new console application.
  • Add the following references.
     
    • Microsoft.SharePoint.dll
    • Microsoft.SharePoint.Taxonomy.dll

  • Add the following namespaces.
     
    • Using Microsoft.SharePoint;
    • Using Microsoft.Sharepoint.Taxonomy;

Create a new group in a term store:

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.CreateGroup("SharePoint Group");
                termStore.CommitAll();
            }
        }
    }
}


taxonomy1.gif

Get all the groups of a particular term store:

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"];
                GroupCollection groupColl = termStore.Groups;
                foreach (Group group in groupColl)
                {
                    Console.WriteLine(group.Name);
                    Console.WriteLine(group.Id);
                }
                Console.ReadLine();
            }
        }
    }
}

taxonomy2.gif