How to provision the Taxonomy group at the site collection level?

Today I will explain “How to provision the Taxonomy group” at the site collection level using client side object model in the SharePoint online using provider hosted Add-in”. Many blogs explained the same scenario, but the wired thing is “How to provision the Taxonomy group, Term sets and Terms from xml file using csom programmatically?” and “How to create nested level terms under the term sets?”

What is Term store management tool in the SharePoint?

Purpose of Term store management tool is to create the terms and term sets. It can manage a terms such as copying and moving. If you want to add many terms, it is better to do with practical example to import all terms in the term set instead of adding the terms individually.

You will find the Term store management tool in site collection by following this link

https://domain.sharepoint.com/sites/mspractice/_layouts/15/termstoremanager.aspx

Note: To create and manage terms in the Term store management tool, you must be a Contributor, a Group Manager, or a Term store Admin.

taxonomy

What is Provider hosted Add-in?

SharePoint Provider hosted Add-ins are applications that run in a server that is external to SharePoint. It has its own infrastructure and the Provider is responsible for keeping it running. They allow you to use CSOM.

For learning more about Provider hosted Add-in follow the msdn link

https://msdn.microsoft.com/en-us/library/office/fp142381.aspx

The moment you create a Provide hosted Add-in the SharePoint, it will create a two projects

  • SharePoint project
  • Web application

To provision the Taxonomy group, Term sets and Terms from xml file using csom programmatically, follow the below steps

  • Add the reference of “Microsoft.SharePoint.Client.Taxonomy” assembly to your project and include namespace “using Microsoft.SharePoint.Client.Taxonomy;”
  • Create xml file name as TermStore.xml and add it to your provider hosted web project.

 

  • Generate the xsd file for the TermStore.xml file.

schema

 

  • Copy the .xml and .xsd files to your local drive (for example in the E drive)
  • Open the visual studio command prompt and navigate to your drive and generate the class file by running “xsd TermStore.xsd /classes” command in the Visual studio command prompt.

Cmd

  • Add the TermStore.cs file to your Provider hosted add-in web project.
  • Add the below class file to your project.

 

  • Open the Default.aspx.cs file in the Provider hosted Add-in web project and add below 2 lines code in the Page load method.

 

  • Save the application and run the application. It will create the new term store group with term sets and terms as a given format.

Termstore