How to get all the term labels for a particular language using Client Side Object Model in SharePoint 2013



Navigate to the Central Administration. Click on Application Management. Click on Manage service applications which is available under Service Applications. Click on MMS (Managed Metadata Service). Expand MMS termstore in the Taxonomy Term Store where all the groups for that particular termstore will be displayed. I have a group called “SP2013” which has the following term sets and terms

Ø  Apps

Ø  BCS

Ø  External Content Type

Ø  External Data Column

Ø  External List

Ø  MMS

Ø  WAS

Select the term on the right hand side you could be able to see the term properties. I have the following labels for the term External Content Type (For English Language).

Default Label

Ø  External Content Type

Other Labels

Ø  ECT

In this blog you will see how to get all the labels (For English Language) for External Content Type term in BCS term set.

 Steps Involved:

1.       Open Visual Studio 2012 (Run as administrator).

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.       Open 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.Client;

using Microsoft.SharePoint.Client.Taxonomy;

using System.Collections.ObjectModel;

 

namespace ManagedMetadataClient

{

    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 term group by Name

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

 

            // Get the term set by Name

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

 

            // Get the term by Name

            Term term = termSet.Terms.GetByName("External Content Type");

 

            // int variable - LCID

            int lcid = 1033;

 

            // Get all the labels for English language

            LabelCollection labelColl = term.GetAllLabels(lcid);

 

            clientContext.Load(labelColl);

 

            // Execute the query to the server

            clientContext.ExecuteQuery();

 

            // Loop through all the labels

            foreach (Label label in labelColl)

            {

                // Display the label value

                Console.WriteLine(label.Value);

            }

            Console.ReadLine();  

        }

    }

}

 


[Note: Site Collection http://c4968397007/ is associated with MMS service application].