Introduction
In this article, we explore how to Set the List/libraries View Experience Modern to Classic, using CSOM Programmatically.
In SharePoint Modern Lists and Libraries, View experience is set to default, under advanced settings and the List experience section is set to "Default experience for the site.
Please note, that this is the default setting. If I change this manually to "new experience" it works. However, we explore how to enable this programmatically.
Pre-requisite
Once the Console Application is created, then you can add the SharePoint PnP dll. To add, click on “Solution Explorer “-> Right click on your solution name-> “Manage NuGet Packages “.
Follow the numerical point, as shown in the below screenshot.
Scenario
The customer requirements of the List/libraries, in the applications, are required to be opening default views into Classic Experience.
Objective
Before starting the implementation code, I would like to explore PnP Site core component. We use this application, PnP CSOM Extension, to connect to SharePoint's online site. You can use the authentication manager, which helps to retrieve the client context, of the provided site.
PnP site core provides the functionality “AuthenticationManager “class to get the client context, by simply passing the following parameter - site url, username, and password.
Note
No Need to install “Microsoft.SharePointOnline.CSOM”, using Manage NuGet Packages, because when we install “SharePointPnPCoreOnline” dll then automatically adds in reference.
Follow the below steps,
Creating a EnableListClassicExperience Console Application
Step 1
Open visual studio --> under file menu select the option new -->select project
Step 2
On left side, select Templates --> select Visual C# and select the Console Application.
Give EnableListClassicExperience for the application. Now, our Solution Explorer looks as follows,
Step 3
After creating an application, by default, it will create a Program.cs file. Add the following code and required two references, used in the sample are below,
- Microsoft.SharePoint.Client
- OfficeDevPnP.Core.Entities
Steps 4
Code snippet for the Program.cs file,
- using System.Configuration;
- using Microsoft.SharePoint.Client;
- using PnPAuthenticationManager = OfficeDevPnP.Core.AuthenticationManager;
- namespace EnableListClassicExperience
- {
- class Program
- {
- static string _sponlinePwd = ConfigurationManager.AppSettings["sponlinePwd"];
- static string _sponlineUseid = ConfigurationManager.AppSettings["SPonlineUser"];
- static string _siteUrl = ConfigurationManager.AppSettings["SPonlineSiteURL"];
- static PnPAuthenticationManager authenticationManager = new PnPAuthenticationManager();
- private static ClientContext oClientContext;
- static void Main(string[] args)
- {
- using (oClientContext = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant(_siteUrl, _sponlineUseid, _sponlinePwd))
- {
- List employeeList = oClientContext.Web.GetListByTitle("EmployeeInformation");
- oClientContext.Load(employeeList.Fields);
- oClientContext.ExecuteQuery();
-
- if (employeeList.ListExperienceOptions != ListExperience.ClassicExperience)
- {
- employeeList.ListExperienceOptions = ListExperience.ClassicExperience;
- employeeList.Update();
- }
- oClientContext.ExecuteQuery();
- }
- }
- }
- }
Step 5
The final step, is to build and deploy.
Output
The final outcome will look, as in the following,
Before - Modern View Experience
After Code Implementation - Classic View Experience
List experience set Classic exprience