ARTICLE

Taxonomy TermSets in SharePoint 2010

Posted by Vijai Anand Articles | SharePoint 2010 February 24, 2011
This article is about the TermSet in SharePoint.
Reader Level:


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();
}
}
}
}

Login to add your contents and source code to this article
comments
COMMENT USING
PREMIUM SPONSORS
Infragistics is experts in technology and design, and passionate about helping you build highly performant and stylish applications that solve problems, deliver inspiration, and maximize results.
Nevron Diagram
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.