New CSOM Version Released For SharePoint Online

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.

  • Manage regional settings of a site
  • Manage language settings of a site
  • Manage auditing settings of a site
  • Control advanced settings for document sets
  • Support for future enhanced migration APIs
  • Control sandbox solution settings at the site collection level
  • Secondary contact in site collection level
  • Sharing settings
Currently the package is updated in the Nuget Gallery. The following assemblies get the updates from the previous release.
  • Microsoft.SharePoint.Client
  • Microsoft.SharePoint.Client.Publishing
  • Microsoft.SharePoint.Client.Search
  • Microsoft.SharePoint.Client.UserProfiles
  • Microsoft.SharePoint.Client.DocumentManagement
  • Microsoft.SharePoint.Client.Tenant
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:
  • Open Visual Studio and create a new project. For this example I have selected Console Application.
  • After project creation, right-click the project name.
  • From the properties popup, select Manage NuGet Packages.
  • In the dialog box, search for the SharePoint Online Object Model
    Add the latest CSOM assemblies as references to the project
  • The search results show you the “SharePoint Online Object Model” package with the version 16.1.3912.1204 at the top. Click the Install button to download and install the package.
  • Before installation, it asks for License acceptance, click the I Accept button to install into your machine.
  • After installation close the dialog box and the DLLs from the package are automatically added as a reference to the project.
  • After the reference is added, I have used the some new properties and methods to show you an example.
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.   
  9.     // Actual code for operations  
  10.     Web web = ctx.Web;  
  11.     RegionalSettings regSettings = web.RegionalSettings;  
  12.     ctx.Load(web);  
  13.     ctx.Load(regSettings); //To get regional settings properties  
  14.     Microsoft.SharePoint.Client.TimeZone currentTimeZone = regSettings.TimeZone;  
  15.     ctx.Load(currentTimeZone);  //To get the TimeZone propeties for the current web region settings  
  16.     ctx.ExecuteQuery();  
  17.       
  18.     //Get the current site TimeZone  
  19.     Console.WriteLine(string.Format("Connected to site with title of {0}", web.Title));      
  20.     Console.WriteLine("Current TimeZone Settings: " + currentTimeZone.Id.ToString() +" - "+ currentTimeZone.Description);  
  21.   
  22.     //Update the TimeZone setting to (UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi. TimeZone Id is 23  
  23.     TimeZoneCollection globalTimeZones = RegionalSettings.GetGlobalTimeZones(ctx);  
  24.     ctx.Load(globalTimeZones);  
  25.     ctx.ExecuteQuery();  
  26.   
  27.     Microsoft.SharePoint.Client.TimeZone newTimeZone = globalTimeZones.GetById(23);  
  28.     regSettings.TimeZone = newTimeZone;  
  29.     regSettings.Update();  //Update New settings to the web  
  30.     ctx.ExecuteQuery();  
  31.   
  32.     Console.WriteLine("New TimeZone settings are updated.");      
  33.     Console.ReadLine();  
  34. }  
Console Output



Browser Output


Up Next
    Ebook Download
    View all
    Learn
    View all