Compartilhar via


How to: Set the Culture and Language

Applies to: SharePoint Foundation 2010

Available in SharePoint Online

If your code runs outside the context of Microsoft SharePoint Foundation and calls into the SharePoint Foundation object model, when the code executes, the culture of the current thread is set according to the operating system settings of the computer on which the code is run. To interact with SharePoint Foundation, the current culture's user interface and formatting must be set to the values that are contained, respectively, in the Language and Locale properties of the SPWeb class. For properties in the object model that switch based on language in the multi-lingual user interface, the current UI culture also controls how to get or set the property values.

Use the CurrentUICulture property to specify the language text to load and the CurrentCulture property to specify the formatting of numbers, date/time values, and so on. Following is an example of how to set these properties. Specifically, only the CC-SSSS-LL values that have language packs in SharePoint Foundation will work correctly when you set CurrentUICulture.

System.Threading.Thread.CurrentThread.CurrentUICulture = 
    New CultureInfo("de-DE", false)
System.Threading.Thread.CurrentThread.CurrentCulture = 
    New CultureInfo("de-DE", false)
System.Threading.Thread.CurrentThread.CurrentUICulture = 
    new CultureInfo("de-DE", false); 
System.Threading.Thread.CurrentThread.CurrentCulture = 
    new CultureInfo("de-DE", false);

As done in the example, it is best practice to use the CultureInfo.CultureInfo(String, Boolean) constructor and pass the Boolean parameter value as false. This is because the default action is to pick the operating system user settings for that culture, which might be different across servers in the farm.

In the example, the CultureInfo() constructor requires that a using directive (Imports in Microsoft Visual Basic) be included for the System.Globalization namespace.

See Also

Concepts

Converting Date and Time Values

Understanding the Multilingual User Interface (MUI)

SharePoint Development Tasks - How Do I...?

Working with List Objects and Collections

Other Resources

Basic Object Model Tasks in SharePoint 2010