A requirement I came across recently was to write a tool to set a site’s locale from US to UK using the object model. Because I potentially needed to do this for hundreds of sites I opted to write a small command line tool that can be scripted to help with the task.
Below is an overview of how to use the SPLocale class to set the Locale of a site. I have also provided download links for the compiled command line tool and its source code for you to take a look at.
First thing we need to do is grab an instance of the site:
SPSite site = new SPSite(“localhost”);
Next thing we do is get a collection of all the web sites under your site:
SPWebCollection webCollection = site.AllWebs;
We can now interate over this collection and set the Locale property to your new locale which will be an instance of the CultureInfo class. We create a new instance of the CultureInfo class by passing the new Locale’s LCID value to it’s constructor.
foreach (SPWeb web in webCollection)
web.Locale = new System.Globalization.CultureInfo(2057);
Thats basically all there is to it.
Example of command line: SPSiteLocale.exe set http://localhost 2057