Set Regional Settings in SharePoint using CSOM

The example in this topic show how to use CSOM to Set Regional Settings in SharePoint

  • using Microsoft.SharePoint.Client;
  • using System.Linq;
  •  
  • using (ClientContext clientContext = new ClientContext("http://MyServer/sites/MySiteCollection"))
  • {
  • Web targetWeb = clientContext.Web;
  • RegionalSettings regionalSettings = targetWeb.RegionalSettings;
  • clientContext.Load(targetWeb, w => w.RegionalSettings, w => w.RegionalSettings.TimeZones);
  • clientContext.ExecuteQuery();
  •  
  • // Note: The Locale ID controls the numbering, sorting, calendar, and time formatting for the Web site
  • // 1033 is for English (United States)
  • targetWeb.RegionalSettings.LocaleId = uint.Parse("1033");
  •  
  • // Set Work Start Time
  • targetWeb.RegionalSettings.WorkDayStartHour = 8;
  •  
  • // Set Work End Time
  • targetWeb.RegionalSettings.WorkDayEndHour = 5;
  •  
  • // Work days: 127 = All, 0 = None, 64 = Sunday, 32 = Monday, 16 = Tuesday
  • // 8 = Wednesday, 4 = Thursday, 2 = Friday, 1 = Sunday, 62 = Monday to Friday
  • targetWeb.RegionalSettings.WorkDays = 62;
  •  
  • // Specify whether you want to use 12-hour time format or 24-hour format.
  • targetWeb.RegionalSettings.Time24 = true;
  •  
  • // Specify a secondary calendar that provides extra information on the calendar features
  • // 1 = Gregorain(Localized), 2 = Gregorian (always English strings), 3 = Japanese Era: Year of the Emperor
  • // 4 =        Year of Taiwan, 5 = Tangun Era (Korea),6 = Hijri, 7 = Thai
  • targetWeb.RegionalSettings.AlternateCalendarType = 1;
  •  
  • // Specify the type of calendar
  • // 0 — None, 1 — Gregorian, 3 — Japanese Emperor Era, 5 — Korean Tangun Era
  • // 6 — Hijri, 7 — Buddhist, 8 — Hebrew Lunar,  9 — Gregorian Middle East French Calendar
  • // 10 — Gregorian Arabic Calendar, 11 — Gregorian Transliterated English Calendar
  • // 12 — Gregorian Transliterated French Calendar, 16 — Saka Era
  • targetWeb.RegionalSettings.CalendarType = 1;
  •  
  • // Set first day of week
  • // 0 = Sunday and 6 = Saturday(last day)
  • targetWeb.RegionalSettings.FirstDayOfWeek = 1;
  •  
  • // Set first week of year
  • // 0 = Starts on Jan 1, 1 = First full week, 2 = First 4-day week
  • targetWeb.RegionalSettings.FirstWeekOfYear = 1;
  •  
  • // Show week numbers in the Date Navigator
  • targetWeb.RegionalSettings.ShowWeeks = true;
  •  
  • Microsoft.SharePoint.Client.TimeZone utcTimeZone = targetWeb.RegionalSettings.TimeZones.Where(timezone => timezone.Description == "(UTC-10:00) Hawaii").First();
  •  
  • targetWeb.RegionalSettings.TimeZone = utcTimeZone;
  •  
  • targetWeb.RegionalSettings.Update();
  • clientContext.ExecuteQuery();
  • }

Thank you for reading this article. This code was tested in SharePoint 2013

We value your feedback:

Page URL:

Name:

 

Email:

 
 

Feedback:

 

© 2019 Code SharePoint