Microsoft recently released the updated SharePoint CSOM package version for SharePoint Online. Based on the updated version I'll walk through an example using Visual Studio.

Before getting into the example, we will see the key changes updated over that version, 16.1.3912.1204.

Currently the package is updated in the Nuget Gallery. The following assemblies get the updates from the previous release.
Let's we move into the main part of the article that will walk through the following items as in the following:
  1. How to connect the Nuget Package from Visual Studio
  2. Attach the latest CSOM Package (16.1.3912.1204) as a reference to the project
  3. Do the code to use the new members in a new Visual Studio Project
The following dscribes how to connect the Nuget package from Visual Studio:
Example Program

The example program gets the current Time Zone settings from the given SharePoint site and update with a new Time zone.

Insert the following code in the console application and get the output as timezone changes for the site.

RegionalSettings, TimeZone and TimeZoneCollection are the new members updated in the CSOM pacakage for SharePoint Online.

Use this link SharePoint Time Zone Collection to determine the id for the appropriate global time zones.
  1. // Get access to source site
  2. using (var ctx = new ClientContext("https://myspworksin.sharepoint.com"))
  3. {
  4. //Provide count and pwd for connecting to the source
  5. var passWord = new SecureString();
  6. foreach (char c in "<mypassword>".ToCharArray()) passWord.AppendChar(c);
  7. ctx.Credentials = new SharePointOnlineCredentials("<office 365 mail id>", passWord);
  8. // Actual code for operations
  9. Web web = ctx.Web;
  10. RegionalSettings regSettings = web.RegionalSettings;
  11. ctx.Load(web);
  12. ctx.Load(regSettings); //To get regional settings properties
  13. Microsoft.SharePoint.Client.TimeZone currentTimeZone = regSettings.TimeZone;
  14. ctx.Load(currentTimeZone); //To get the TimeZone propeties for the current web region settings
  15. ctx.ExecuteQuery();
  16. //Get the current site TimeZone
  17. Console.WriteLine(string.Format("Connected to site with title of {0}", web.Title));
  18. Console.WriteLine("Current TimeZone Settings: " + currentTimeZone.Id.ToString() +" - "+ currentTimeZone.Description);
  19. //Update the TimeZone setting to (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi. TimeZone Id is 23
  20. TimeZoneCollection globalTimeZones = RegionalSettings.GetGlobalTimeZones(ctx);
  21. ctx.Load(globalTimeZones);
  22. ctx.ExecuteQuery();
  23. Microsoft.SharePoint.Client.TimeZone newTimeZone = globalTimeZones.GetById(23);
  24. regSettings.TimeZone = newTimeZone;
  25. regSettings.Update(); //Update New settings to the web
  26. ctx.ExecuteQuery();
  27. Console.WriteLine("New TimeZone settings are updated.");
  28. Console.ReadLine();
  29. }
Console Output



Browser Output