How to Change the Calendar Type in the Regional Settings Using CSOM in SharePoint 2013 Online
In this blog you will see how to change the Calendar Type in the regional settings using CSOM in SharePoint 2013 Online.
Code Snippet:
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Security;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.SharePoint.Client;
-
- namespace CSOMOffice365
- {
- class Program
- {
- static void Main(string[] args)
- {
-
- string userName = "[email protected]";
-
- Console.WriteLine("Enter your password.");
- SecureString password = GetPassword();
-
-
-
-
- using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
- {
-
- clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
-
-
- Web web = clientContext.Web;
-
-
-
- RegionalSettings regSet = web.RegionalSettings;
-
-
- regSet.CalendarType = 5;
- regSet.AlternateCalendarType = 5;
-
-
- regSet.Update();
- clientContext.Load(regSet);
-
-
- clientContext.ExecuteQuery();
-
-
- Console.WriteLine("Calendar Type: " + regSet.CalendarType + "; Alernate Calendar Type: " + regSet.AlternateCalendarType);
- Console.ReadLine();
- }
- }
-
- private static SecureString GetPassword()
- {
- ConsoleKeyInfo info;
-
-
- SecureString securePassword = new SecureString();
- do
- {
- info = Console.ReadKey(true);
- if (info.Key != ConsoleKey.Enter)
- {
- securePassword.AppendChar(info.KeyChar);
- }
- }
- while (info.Key != ConsoleKey.Enter);
- return securePassword;
- }
- }
- }
Result