Enable new look for SharePoint libraries using CSOM

For a while now Microsoft has been rolling out the new look for document libraries. At first I didn’t like it, but everything new takes time to learn and get used to. However our customers found that they prefer the new look and asked us to change all libraries to it.
There are 3 options for controling the look which are outlined here. After we updated settings in the SharePoint admin center we found that not all libraries got the new look. Perhaps because the look was set on each library individually. So the only option was to control the look at the site or website level.

Instructions in the MS article tell us to use Powershell with CSOM, and of course, for us coders it’s just easier to use CSOM without powershell, so here is extracted code.

1.To setup to use new look for all libraries in a site collection by default:

Guid featureguidSite = Guid.Parse("E3540C7D-6BEA-403C-A224-1A12EAFEE4C4");
clientContext.Site.Features.Remove(featureguidSite, true);
clientContext.ExecuteQuery();

Notice that we need to remove a feature to enable the new look, this is not a mistake.

2.To revert to a classic look for all libraries by default

clientContext.Site.Features.Add(featureguidSite, true, Microsoft.SharePoint.Client.FeatureDefinitionScope.None);
clientContext.ExecuteQuery();

3.To setup to use new look for all libraries in a website by default

Web web = clientContext.Site.RootWeb;
Guid featureguidWeb = Guid.Parse("52E14B6F-B1BB-4969-B89B-C4FAA56745EF");
web.Features.Remove(featureguidWeb, true);
clientContext.ExecuteQuery();

Substitute your web here. Notice that it’s a different feature for a website than for a site collection.

4.To revert to a classic look for all libraries by default

web.Features.Add(featureguidWeb, true, Microsoft.SharePoint.Client.FeatureDefinitionScope.None);
clientContext.ExecuteQuery();

That’s all. Happy coding!