In this article we will be seeing how to delete Term, TermSet and Group in SharePoint.
In this article we will be seeing the following:
- Delete a Term
- Delete a TermSet
- Delete a Group
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;
Delete a Term:
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.TermSets["Word Automation Services"];
Term term = termSet.Terms["Conversion"];
term.Delete();
termStore.CommitAll();
}
}
}
}
Delete a TermSet:
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://servcerName:10/"))
{
TaxonomySession taxonomySession = new TaxonomySession(site);
TermStore termStore = taxonomySession.TermStores["MMS"];
Group group = termStore.Groups["SharePoint Group"];
TermSet termSet = group.TermSets["Word Automation Services"];
termSet.Delete();
termStore.CommitAll();
}
}
}
}
Delete a Group:
When you try to delete the group you will be getting the following error