top of page
Writer's pictureVijai Anand Ramalingam

Introduction In this article you will see how to remove a group from a SharePoint site using a NINT

In this article you will see how to set a custom sort order for the taxonomy terms in SharePoint 2013 using the server object model.

Introduction

I have created a taxonomy group in which I have a termset. In the termset I have created a few terms. I want to change the order of the child terms for a particular term using the SharePoint object model. In this article you will see how to do custom sort order for taxonomy terms using SharePoint object model. Open Central Administration. Click on "Application Management". Click on "Manage service applications" available under Service Applications. Click on "Managed Metadata Service Application".


Select the "Term2"; on the right hand side you will see the properties of the term. Click on the "CUSTOM SORT" tab; by default "Use default sort order according to current language" will be selected. In this article you will see how to set a custom sort order using the SharePoint Object model.

Procedure

  • Open Visual Studio 2012 (Run as administrator).

  • Go to "File" => "New" => "Project...".

  • Select "Console Application" in the Visual C# node from the installed templates.

  • Enter the Name and click on "OK".

  • In the Solution Explorer, right-click on the References folder and then click on "Add Reference".

  • Add the following assemblies from hive 15 (C:\Program Files\Common Files\Microsoft shared\Web Server Extensions\15\ISAPI).

  1. Microsoft.SharePoint.dll

  2. Microsoft.SharePoint.Taxonomy.dll

  • Open the Program.cs file and replace the code with the following:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.SharePoint; using Microsoft.SharePoint.Taxonomy; using System.Collections.ObjectModel;

namespace TaxonomyCodeSamples { class Program Ā Ā Ā  { static void Main(string[] args) Ā Ā Ā Ā Ā Ā Ā  { using (SPSite site = new SPSite("http://c4968397007/sites/Vijai")) Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  { Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  TaxonomySession taxSession = new TaxonomySession(site); //// Get the term store Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  TermStore termStore = taxSession.TermStores["MMS"]; //// Get the taxonomy group Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  Group group = termStore.Groups["Group"]; //// Get the termset Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  TermSet termSet = group.TermSets["Termset"]; //// Get the particular term for which the child terms has to be sorted Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  Term term = termSet.Terms["Term2"]; //// 09810eaa-3fb3-4fef-bd91-d9ce7941259d - GUID for Term22 //// ca14f1b9-c257-4e99-8e2c-3cc722884b5e - GUID for Term21 //// Set the custom sort order Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  term.CustomSortOrder = "09810eaa-3fb3-4fef-bd91-d9ce7941259d:ca14f1b9-c257-4e99- 8e2c-3cc722884b5e";Ā Ā  //// Commit all the changes Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  termStore.CommitAll(); Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā  } Ā Ā Ā Ā Ā Ā Ā  } Ā Ā Ā  } }


  • Hit F5.

  • You will be able to see the custom sort order as in the following:


Summary

Thus in this article you have seen how to set a custom sort order for the taxonomy terms in SharePoint 2013 using the server object model.

0 comments

Comments


bottom of page