Advertisement

Responsive Advertisement

O365- Programmatically Create New Term Store Management in SharePoint Online-CSOM


Introduction:
This article helps you create new Term Group using CSOM method.
In this article helps you to find out how to create new term store management in SharePoint2013 online. The SharePoint 2013 term store is a “farm” level repository of hierarchical term sets and terms used by SharePoint for both metadata and navigation.
In this article will help you to create new Term Group.NewTermSet, and New term within the term store management.
Prerequisites:
Add the following assemblies from 15 hive (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI).
a.       Microsoft.SharePoint.Client.dll
b.      Microsoft.SharePoint.Client.Runtime.dll
c.       Microsoft.SharePoint.Client.Taxonomy.dll


To create and manage terms in the Term Store management tool, you must be a Contributor, a Group Manager, or a Term Store Administrator. To create a new term set group, you must be a Term Store Administrator. When you create a new group, it is a global group. 
Follow the beow steps to execute the code,
1.       Open Visual Studio 2012 
2.       Go to File=> New => Project.
3.       Select Console Application in the Visual C# node from the installed templates.
4.       Enter the Name and click on Ok.
5.       In the solution explorer, right click on References folder and then click on Add Reference.
6.       Add the following assemblies from 15 hive (C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI).
a.       Microsoft.SharePoint.Client.dll
b.      Microsoft.SharePoint.Client.Runtime.dll
c.       Microsoft.SharePoint.Client.Taxonomy.dll
7.       copy the below code an paste in your IDE.


Create Term Group:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using System.Collections.ObjectModel;
namespace NewtermStoremanagement
{
   class Program
   {
       static void Main(string[] args)
       {
           string termGroupName="NewTermGroup";
           ClientContext clientContext = new ClientContext("https://gowthamr-admin.sharepoint.com/");
           TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
           TermStore termStore = taxonomySession.TermStores.GetByName("MMS");
           TermGroup termGroup = termStore.CreateGroup(termGroupName, Guid.NewGuid());
           clientContext.ExecuteQuery();
       }
   }
}


Create New Term Set:
A term set is a group of related terms.
  • Local term sets    are created within the context of a site collection, and are available for use (and visible) only to users of that site collection
  • Global term sets    are available for use across all sites that subscribe to a specific Managed Metadata Service application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Taxonomy;
using System.Collections.ObjectModel;

namespace NewtermStoremanagement
{
    class Program
    {
        static void Main(string[] args)
        {
         
            ClientContext clientContext = new ClientContext("https://gowthamr-admin.sharepoint.com/");
            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
            TermStore termStore = taxonomySession.TermStores.GetByName("MMS");          
            Guid guid = new Guid("f05e3a3a-884f-4feb-c32a-49735f3fb7f7");          
            TermGroup termGroup = termStore.GetGroup(guid);
            string termSetName="NewTermSet";          
            Guid newTermSetGuid=Guid.NewGuid();          
            int lcid=1033;          
            TermSet termSetColl = termGroup.CreateTermSet(termSetName, newTermSetGuid, lcid);    
            clientContext.ExecuteQuery();
        }
    }
}

Create a Term:




Conclusion:

This article will helps you to understand about Term Store management in SharePoint Online using client object model .The next article will see about how to create a MMS service in PowerShell method.

Post a Comment

0 Comments