Programmatically get the LCID of the default language for the termstore in SharePoint 2010


I have a site collection which is associated with the Managed Metadata Service Application. It has a termstore called "Managed Metadata Service". Here we will see how to get the LCID for the default working language for the provided termstore (Managed Metadata Service termstore).

Navigate to the Site Collection
http://serverName:11111/sites/MMS/. Go to Site Actions, click on Site Settings. Click on Term Store Management under Site Collection Administration section. You could be able to see the Managed Metadata Service Termstore. In the properties panel you could be able to see an section Default Language. In this blog you will see how to get that default language using SharePoint Object Model.

Steps Involved:

  1. Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.
  2. Go to File tab, click on New and then click on Project.
  3. In the New Project dialog box, expand the Visual C# node, and then select the Windows node.
  4. In the Templates pane, select Console Application.
  5.  Enter the Name as TaxonomyTermStores and then click OK.
  6.  In the solution explorer, right click on the solution and then click on Properties.
  7. Select the Application tab, check whether “.Net Framework 3.5” is selected for Target Framework.
  8. Select the Build tab, check whether “Any CPU” is selected for Platform Target.
  9. Add the following references

     Microsoft.SharePoint 
Microsoft.SharePoint.Taxonomy 

  1. Add the following namespaces

        using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;

  1. Replace Program.cs with the following code

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using Microsoft.SharePoint;

using Microsoft.SharePoint.Taxonomy;

 

namespace TaxonomyTermStores

{

    class Program

    {

        static void Main(string[] args)

        {

            using (SPSite site = new SPSite("http://serverName:11111/sites/MMS/"))

            {

                ////TaxonomySession class is used to wrap up all of the associated TermStore objects for a SPSite object.

                TaxonomySession session = new TaxonomySession(site);

                ////Get the particular term store associated with the site

                TermStore termStore = session.TermStores["Managed Metadata Service"];

                ////Get the LCID of the default working language for this TermStore

                Console.WriteLine(termStore.DefaultLanguage);               

                Console.ReadLine();              

              

            }

        }

    }

}

Ebook Download
View all
Learn
View all