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.
How To Revert Modern View Back To Classic In SharePoint Online List / Libraries Using CSOM 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.
How To Revert Modern View Back To Classic In SharePoint Online List / Libraries Using CSOM Programmatically

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,
How To Revert Modern View Back To Classic In SharePoint Online List / Libraries Using CSOM Programmatically
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,
  1. using System.Configuration;
  2. using Microsoft.SharePoint.Client;
  3. using PnPAuthenticationManager = OfficeDevPnP.Core.AuthenticationManager;
  4. namespace EnableListClassicExperience
  5. {
  6. class Program
  7. {
  8. static string _sponlinePwd = ConfigurationManager.AppSettings["sponlinePwd"];
  9. static string _sponlineUseid = ConfigurationManager.AppSettings["SPonlineUser"];
  10. static string _siteUrl = ConfigurationManager.AppSettings["SPonlineSiteURL"];
  11. static PnPAuthenticationManager authenticationManager = new PnPAuthenticationManager();
  12. private static ClientContext oClientContext;
  13. static void Main(string[] args)
  14. {
  15. using (oClientContext = authenticationManager.GetSharePointOnlineAuthenticatedContextTenant(_siteUrl, _sponlineUseid, _sponlinePwd))
  16. {
  17. List employeeList = oClientContext.Web.GetListByTitle("EmployeeInformation");
  18. oClientContext.Load(employeeList.Fields);
  19. oClientContext.ExecuteQuery();
  20. if (employeeList.ListExperienceOptions != ListExperience.ClassicExperience)
  21. {
  22. employeeList.ListExperienceOptions = ListExperience.ClassicExperience; //Set this Classic List view Experience
  23. employeeList.Update();
  24. }
  25. oClientContext.ExecuteQuery();
  26. }
  27. }
  28. }
  29. }
Step 5
The final step, is to build and deploy.

Output

The final outcome will look, as in the following,
Before - Modern View Experience
How To Revert Modern View Back To Classic In SharePoint Online List / Libraries Using CSOM Programmatically
After Code Implementation - Classic View Experience
How To Revert Modern View Back To Classic In SharePoint Online List / Libraries Using CSOM Programmatically
List experience set Classic exprience
How To Revert Modern View Back To Classic In SharePoint Online List / Libraries Using CSOM Programmatically