Latest Posts

Set Regional Settings in SharePoint using CSOM

The example in this topic show how to use CSOM to Set Regional Settings in SharePoint
  • Please follow the steps below to execute the code in Visual Studio using Console Application. You can customize the solution according to your requirements.
  • Check the article to Connect to SharePoint context using CSOM. This is very helpful if you are doing any programming in CSOM.
  • Don't forget to use the assemblies as mentioned in the code.

How to run CSOM code in SharePoint?

  • Open your Visual Studio.
  • From the template, select Console Application as shown in the screenshot
  • Select the .Net Framework version from the top drop-down as well. You can also change the .Net Framework after creating the solution.
  • Enter Project Name, Location and Solution Name and click on OK.
  • create console application using Visual Studio
  • Now your program.cs file will open. Copy the code in main function.
  • Once you are done with your code, just hit F5 or Run the application.

  • 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:

 
 

Suggestion:

 

© 2024 Code SharePoint