Change Locale of SharePoint Site Programatically

n

nWhile working with SharePoint sites, we can change the regional settings of the site by using user interface and that’s easy to be done

n

nYou can do it like

n

nClick on Site Actions > Site Settings > Click on Regional Settings link under Site Administration

n

nand this is the small code using which you as a developer can do

n

nI have used hardcoding here to Initialize CultureInfo object but you can do customizations according to your need

n

n

n

nI hope this helps some one J

n
n

n
n

nnamespace ChangeCulture

nn

n{

n

n  class Program

n

n  {

n

n    static void Main(string[] args)

n

n    {

n

n      using (SPSite site = new SPSite(“http://yoursite”))

n

n      {

n

n        try

n

n        {

n

n          using (SPWeb web = site.RootWeb)

n

n          {

n

n            ChangeCulture(web);

n

n          }

n

n         }

n

n        catch (Exception ex)

n

n        {

n

n         Console.WriteLine(string.Format(“{0}:{1}”, “Error: “, ex.Message));

n

n        }

n

n       }

n

n      }

n

n

n

n    private static void ChangeCulture(SPWeb web)

n

n    {

n

n

n

n      if (web != null)

n

n      {

n

n        web.AllowUnsafeUpdates = true;

n

n

n

n        //Initialize CultureInfo

n

n        CultureInfo ci = new CultureInfo(“en-US”);

n

n

n

n        if (ci != null)

n

n        {

n

n          string.Format(“{0}{1}”, “Processing “, web.Name);

n

n          web.Locale = ci;

n

n          web.Update();

n

n        }

n

n

n

n         web.AllowUnsafeUpdates = false;

n

n       }

n

n

n

n       if (web != null)

n

n       {

n

n         foreach (SPWeb _web in web.Webs)

n

n         {

n

n           ChangeCulture(_web);

n

n         }

n

n       }

n

n

n

n

n

n     }

n

n    }

n

n}

n

Leave a Comment