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();
- // ClienContext - Get the context for the SharePoint Online Site
- // SharePoint site URL - https://c986.sharepoint.com
- using (var clientContext = new ClientContext("https://c986.sharepoint.com"))
- {
- // SharePoint Online Credentials
- clientContext.Credentials = new SharePointOnlineCredentials(userName, password);
- // Get the SharePoint web
- Web web = clientContext.Web;
- // Regional Settings
- RegionalSettings regSet = web.RegionalSettings;
- // Work days: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.workdays.aspx
- // Convert the binary value to decimal: 0110110 - 54
- regSet.WorkDays = 54;
- // First Day of Week: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.firstdayofweek.aspx
- regSet.FirstDayOfWeek = 1;
- // First Week of Year: https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.firstweekofyear.aspx
- regSet.FirstWeekOfYear = 1;
- // Work Day Start Hour - https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.workdaystarthour.aspx
- regSet.WorkDayStartHour = 540;
- // Work Day End Hour - https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.regionalsettings.workdayendhour.aspx
- regSet.WorkDayEndHour = 1020;
- // Update the regional Settings
- regSet.Update();
- // Execute the query to the server
- clientContext.ExecuteQuery();
- }
- }
- private static SecureString GetPassword()
- {
- ConsoleKeyInfo info;
- //Get the user's password as a SecureString
- 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;
- }
- }
- }
Output



Ketak BhalsingPosted May 17, 2016, 2:00 AM
Good info....
Bhuvanesh MohankumarPosted May 12, 2016, 8:54 AM
Good one