Changing the locale of a SPWeb

A little while ago, I was asked to change a SPWeb's locale id through code (or however I managed to accomplish it automatically :p)

So, I created a really small Feature for it, and when the Feature is activated, to following code runs:

public void EditLocale()

{

    using (SPSite site = new SPSite(url))

    {

        using (SPWeb web = site.OpenWeb())

        {

            CultureInfo culture = new CultureInfo("nl-BE");

            web.Locale = culture;

 

            web.AllowUnsafeUpdates = true;

            web.Update();

            web.AllowUnsafeUpdates = false;

        }

    }

}

Nothing special as you see.
Just create a new CultureInfo object (in my case a flemish one), and attach it to the SPWeb.Locale.

(and don't forget to update your SPWeb object). 

Leave a Reply