Export (0) Print
Expand All
Expand Minimize

SPWeb.Language property

Gets the locale identifier (LCID) for the default language of the website.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public uint Language { get; }

Property value

Type: System.UInt32
A 32-bit unsigned integer that indicates the LCID for the language. For a list of LCIDs, see the SPLocale.LCID property.

The default language of a website can be set only when the site is created. A site owner can subsequently turn on alternate languages by using the multilingual user interface or by setting the IsMultilingual property.

The following example is a console application that prints the LCID and display name for each language installed on the farm, the default language of the website, and each alternate language supported by the site.

using System;
using System.Collections.Generic;
using System.Globalization;
using Microsoft.SharePoint;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.RootWeb)
                {
                    string format = "{0} | {1}";

                    // Display the languages installed on the farm.
                    Console.WriteLine("Installed Languages");

                    SPLanguageCollection languages = SPRegionalSettings.GlobalInstalledLanguages;
                    foreach (SPLanguage language in languages)
                    {
                            Console.WriteLine(format, language.LCID, language.DisplayName);
                    }

                    // Display the default language for the website.
                    int lcid = (int)web.Language;
                    CultureInfo defaultCulture = new CultureInfo(lcid);

                    Console.WriteLine("\nDefault Language");
                    Console.WriteLine(format, defaultCulture.LCID, defaultCulture.DisplayName);

                    // Display the alternate languages for the website.
                    if (web.IsMultilingual)
                    {
                        Console.WriteLine("\nAlternate Languages");

                        IEnumerable<CultureInfo> cultures = web.SupportedUICultures;
                        foreach (CultureInfo culture in cultures)
                        {
                            if (culture.LCID == defaultCulture.LCID)
                                continue;

                            Console.WriteLine(format, culture.LCID, culture.DisplayName);
                        }
                    }
                }
            }
            Console.Write("\nPress ENTER to continue....");
            Console.Read();
        }
    }
}
Show:
© 2014 Microsoft