How to Change the Locale for a site using CSOM in SharePoint 2013 Online

Code Snippet 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Net;  
  5. using System.Security;  
  6. using System.Text;  
  7. using System.Threading.Tasks;  
  8. using Microsoft.SharePoint.Client;  
  9.   
  10. namespace CSOMOffice365  
  11. {  
  12.     class Program  
  13.     {  
  14.         static void Main(string[] args)  
  15.         {  
  16.   
  17.             string userName = "[email protected]";  
  18.   
  19.             Console.WriteLine("Enter your password.");  
  20.             SecureString password = GetPassword();  
  21.   
  22.             // ClienContext - Get the context for the SharePoint Online Site  
  23.             // SharePoint site URL - https://c986.sharepoint.com  
  24.   
  25.             using (var clientContext = new ClientContext("https://c986.sharepoint.com"))  
  26.             {  
  27.                 // SharePoint Online Credentials  
  28.                 clientContext.Credentials = new SharePointOnlineCredentials(userName, password);  
  29.   
  30.                 // Get the SharePoint web  
  31.                 Web web = clientContext.Web;  
  32.   
  33.                 //Regional Settings: Set the locale to Hindi - 1081  
  34.                 RegionalSettings regSet = web.RegionalSettings;  
  35.                 regSet.LocaleId = 1081;  
  36.                 regSet.Update();  
  37.                 clientContext.Load(regSet);  
  38.   
  39.                 // Execute the query to the server  
  40.                 clientContext.ExecuteQuery();  
  41.   
  42.                 // Display the updated locale ID  
  43.                 Console.WriteLine(regSet.LocaleId);  
  44.             }  
  45.         }  
  46.   
  47.         private static SecureString GetPassword()  
  48.         {  
  49.             ConsoleKeyInfo info;  
  50.   
  51.             //Get the user's password as a SecureString  
  52.             SecureString securePassword = new SecureString();  
  53.             do  
  54.             {  
  55.                 info = Console.ReadKey(true);  
  56.                 if (info.Key != ConsoleKey.Enter)  
  57.                 {  
  58.                     securePassword.AppendChar(info.KeyChar);  
  59.                 }  
  60.             }  
  61.             while (info.Key != ConsoleKey.Enter);  
  62.             return securePassword;  
  63.         }  
  64.     }  
  65. }  
Result
 
 
Ebook Download
View all
Learn
View all