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. namespace CSOMOffice365
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. string userName = "[email protected]";
  16. Console.WriteLine("Enter your password.");
  17. SecureString password = GetPassword();
  18. // ClienContext - Get the context for the SharePoint Online Site
  19. // SharePoint site URL - https://c986.sharepoint.com
  20. using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
  21. {
  22. // SharePoint Online Credentials
  23. clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
  24. // Get the SharePoint web
  25. Web web = clientContext.Web;
  26. // Regional Settings
  27. RegionalSettings regSet = web.RegionalSettings;
  28. // Work days: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.workdays.aspx
  29. // Convert the binary value to decimal: 0110110 - 54
  30. regSet.WorkDays = 54;
  31. // First Day of Week: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.firstdayofweek.aspx
  32. regSet.FirstDayOfWeek = 1;
  33. // First Week of Year: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.firstweekofyear.aspx
  34. regSet.FirstWeekOfYear = 1;
  35. // Work Day Start Hour - https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.workdaystarthour.aspx
  36. regSet.WorkDayStartHour = 540;
  37. // Work Day End Hour - https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.workdayendhour.aspx
  38. regSet.WorkDayEndHour = 1020;
  39. // Update the regional Settings
  40. regSet.Update();
  41. // Execute the query to the server
  42. clientContext.ExecuteQuery();
  43. }
  44. }
  45. private static SecureString GetPassword()
  46. {
  47. ConsoleKeyInfo info;
  48. //Get the user's password as a SecureString
  49. SecureString securePassword = new SecureString();
  50. do
  51. {
  52. info = Console.ReadKey(true);
  53. if (info.Key != ConsoleKey.Enter)
  54. {
  55. securePassword.AppendChar(info.KeyChar);
  56. }
  57. }
  58. while (info.Key != ConsoleKey.Enter);
  59. return securePassword;
  60. }
  61. }
  62. }
Output