Change Locale of SharePoint Site - Code behind


While working with SharePoint sites, we can change the regional settings of the site by using user interface and that's easily done.

You can do it like:

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

and this is the small code which you as a developer can use

I have used hard coding here to Initialize Culture Info object but you can do customizations according to your need.

I hope this helps some one.

namespace ChangeCulture

{

  class Program

  {

    static void Main(string[] args)

    {

      using (SPSite site = new SPSite("http://yoursite"))

      {

        try

        {

          using (SPWeb web = site.RootWeb)

          {

            ChangeCulture(web);

          }

         }

        catch (Exception ex)

        {

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

        }

       }

      }

    private static void ChangeCulture(SPWeb web)

    {

      if (web != null)

      {

        web.AllowUnsafeUpdates = true;

        //Initialize CultureInfo

        CultureInfo ci = new CultureInfo("en-US");

        if (ci != null)

        {

           Console.WriteLine(string.Format("{0}{1}""Processing ", web.Name));

          web.Locale = ci;

          web.Update();

        }

         web.AllowUnsafeUpdates = false;

       }

       if (web != null)

       {

         foreach (SPWeb _web in web.Webs)

         {

           ChangeCulture(_web);

         }

       }

     }

    }

}

Up Next
    Ebook Download
    View all
    Learn
    View all