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:
- How to connect the Nuget Package from Visual Studio
- Attach the latest CSOM Package (16.1.3912.1204) as a reference to the project
- 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 ProgramThe 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.
-
- using (var ctx = new ClientContext("https://myspworksin.sharepoint.com"))
- {
-
- var passWord = new SecureString();
- foreach (char c in "<mypassword>".ToCharArray()) passWord.AppendChar(c);
- ctx.Credentials = new SharePointOnlineCredentials("<office 365 mail id>", passWord);
-
-
- Web web = ctx.Web;
- RegionalSettings regSettings = web.RegionalSettings;
- ctx.Load(web);
- ctx.Load(regSettings);
- Microsoft.SharePoint.Client.TimeZone currentTimeZone = regSettings.TimeZone;
- ctx.Load(currentTimeZone);
- ctx.ExecuteQuery();
-
-
- Console.WriteLine(string.Format("Connected to site with title of {0}", web.Title));
- Console.WriteLine("Current TimeZone Settings: " + currentTimeZone.Id.ToString() +" - "+ currentTimeZone.Description);
-
-
- TimeZoneCollection globalTimeZones = RegionalSettings.GetGlobalTimeZones(ctx);
- ctx.Load(globalTimeZones);
- ctx.ExecuteQuery();
-
- Microsoft.SharePoint.Client.TimeZone newTimeZone = globalTimeZones.GetById(23);
- regSettings.TimeZone = newTimeZone;
- regSettings.Update();
- ctx.ExecuteQuery();
-
- Console.WriteLine("New TimeZone settings are updated.");
- Console.ReadLine();
- }
Console Output
Browser Output