How to set Custom Sort order for taxonomy terms using CSOM


I have created a taxonomy group in which I have a termset. In the termset I have created few terms. I want to change the order of the child terms for a particular term using SharePoint client side object model. In this blog you will see how to do custom sort order for taxonomy terms using SharePoint client side object model. Please refer http://www.c-sharpcorner.com/UploadFile/anavijai/how-to-set-custom-sort-order-for-taxonomy-terms-in-sharepoin/ to know more about custom sort order for taxonomy terms.


 

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;

 

namespace TaxonomyCodeSamples

{

    class Program

    {

        static void Main(string[] args)

        {

            // ClienContext - Get the context for the SharePoint Site

            // SharePoint site URL - http://c4968397007/

            ClientContext clientContext = new ClientContext("http://c4968397007/");

            // Get the TaxonomySession

            TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);

            // Get the term store by name

            TermStore termStore = taxonomySession.TermStores.GetByName("MMS");

            // Get the taxonomy group by name

            TermGroup termGroup = termStore.Groups.GetByName("Group");

            // Get the termset by name

            TermSet termSet = termGroup.TermSets.GetByName("Termset");

            // Set the sort order for the terms

            termSet.CustomSortOrder = "85e1983a-1ff7-4c46-9004-b64c4a74aa05:b2faeeb7-f9ab-47e9-b525-23cc1b98e394";

            termStore.CommitAll();          

            clientContext.ExecuteQuery();            

        }

    }

}