How to Change the Calendar Type in the Regional Settings 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: Change the calendar type and alternate calendar type  
  34.                 // Reference: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.calendartype.aspx  
  35.                 RegionalSettings regSet = web.RegionalSettings;  
  36.   
  37.                 // Change the calendar type to 5 - Korean Tangun Era  
  38.                 regSet.CalendarType = 5;  
  39.                 regSet.AlternateCalendarType = 5;  
  40.   
  41.                 // Update the regional settings  
  42.                 regSet.Update();  
  43.                 clientContext.Load(regSet);  
  44.   
  45.                 // Execute the query to the server  
  46.                 clientContext.ExecuteQuery();  
  47.   
  48.                 // Display the updated calendar type  
  49.                 Console.WriteLine("Calendar Type: " + regSet.CalendarType + "; Alernate Calendar Type: " + regSet.AlternateCalendarType);  
  50.                 Console.ReadLine();  
  51.             }  
  52.         }  
  53.   
  54.         private static SecureString GetPassword()  
  55.         {  
  56.             ConsoleKeyInfo info;  
  57.   
  58.             //Get the user's password as a SecureString  
  59.             SecureString securePassword = new SecureString();  
  60.             do  
  61.             {  
  62.                 info = Console.ReadKey(true);  
  63.                 if (info.Key != ConsoleKey.Enter)  
  64.                 {  
  65.                     securePassword.AppendChar(info.KeyChar);  
  66.                 }  
  67.             }  
  68.             while (info.Key != ConsoleKey.Enter);  
  69.             return securePassword;  
  70.         }  
  71.     }  
  72. }   
Result 
 
Ebook Download
View all
Learn
View all