5

I have been trying to enable new list experience on a document library programmatically using CSOM C# in my app.

First I checked the settings in the SharePoint admin center where SharePoint Lists and Libraries experience is set to "New experience (auto detect). "

Then I checked the default document library under advanced settings where the List experience is set to "Default experience set by my administrator. " Please note that this is the default setting - if I change this manually to "new experience" it works, however I want to enable this programmatically!

I then tried to google the issue and found this guide to switch the default for document libraries from new or classic here: https://support.office.com/en-us/article/Switch-the-default-for-document-libraries-from-new-or-classic-66dac24b-4177-4775-bf50-3d267318caa9

This pretty much explained what I already knew, but it also explained a way of enabling the new experience by removing a feature on the Site Collection scope or web scope.

Site collection example:

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

Website example:

Guid featureguidWeb = new Guid("52E14B6F-B1BB-4969-B89B-C4FAA56745EF");
context.Web.Features.Remove(featureguidWeb, true);
context.ExecuteQuery();

I have tried the above mentioned code and found that neither feature was enabled.

I have also looked at the SharePoint client site list members here without luck.

So does anyone know of a way to enable the new list experience on document libraries by code? Preferably in CSOM C#.

From what I can read out of the description in SharePoint admin center settings it should work as long as there is no customization enabled on the list - and as it is a default list on the website there should not be any customization? Or am I wrong?

The new experience gives people improved performance, additional phone and tablet features, and a simplified UI. Select the new experience (auto detect) option when you want to use the classic experience for libraries that have features or customizations enabled that only work in the classic experience, and use the new experience for libraries that don't have these features or customizations enabled. If you select the new experience, users can still switch to the classic experience if they want. Select the classic experience if you're not ready for your users to switch to the new experience. Note that eventually, the classic experience will no longer be available.

  • 1
    @AndersNielson you can now use CSOM to update the list experience. – Daniel Gimenez Sep 27 '16 at 14:18
5

There isn't any API that lets you enable it for a document library only that I have found. You can only influence that by setting the library experience on a site or a web. I have the following CSOM adaptation in our PowerShell library.

function Set-NewExperience{
    <#
    .Synopsis
       Sets the document library experience for a site or web
    .DESCRIPTION
       Sets the document library experience for a site or web
    .EXAMPLE
       The following would disable the new experience for an entire site collection
       Set-NewExperience -Url "https://tenant.sharepoint.com/teams/eric" -Scope Site -State Disabled
    .EXAMPLE
       The following would disable the new experience for a single web
       Set-NewExperience -Url "https://tenant.sharepoint.com/teams/eric" -Scope Web -State Disabled
    .EXAMPLE
       The following would enable the new experience for an entire site collection
       Set-NewExperience -Url "https://tenant.sharepoint.com/teams/eric" -Scope Site -State Enabled
    .Link
    https://support.office.com/en-us/article/Switch-the-default-for-document-libraries-from-new-or-classic-66dac24b-4177-4775-bf50-3d267318caa9
    #>
    Param
    (
        [Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true)]
        [string]$Url,
        [Parameter(Mandatory=$true)][ValidateSet("Site", "Web")]
        [string]$Scope,
        [Parameter(Mandatory=$true)][ValidateSet("Enabled", "Disabled")]
        [string]$State

    )

    Begin{
        $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
        $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)
    }
    Process{

        if($Scope -eq "Site"){
            # To apply the script to the site collection level, uncomment the next two lines.
            $site = $context.Site
            $featureguid = new-object System.Guid "E3540C7D-6BEA-403C-A224-1A12EAFEE4C4"
        }
        else{
            # To apply the script to the website level, uncomment the next two lines, and comment the preceding two lines.
            $site = $context.Web
            $featureguid = new-object System.Guid "52E14B6F-B1BB-4969-B89B-C4FAA56745EF" 
        }
        if($State -eq "Disabled")
        {
            # To disable the option to use the new UI, uncomment the next line.
            $site.Features.Add($featureguid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None)
            $message = "New library experience has been disabled on $URL"
        }
        else{
            # To re-enable the option to use the new UI after having first disabled it, uncomment the next line.
            # and comment the preceding line.
            $site.Features.Remove($featureguid, $true)
            $message = "New library experience has been enabled on $URL"
        }
        try{
            $context.ExecuteQuery()
            write-host -ForegroundColor Green $message
        }
        catch{
            Write-Host -ForegroundColor Red $_.Exception.Message
        }
    }
    End{
        $context.Dispose()    
    }
}
  • 1
    From what I've read in the comments this only "re-enables the option to use the new UI...", but it doesn't actually enable it. What is your experience with it? Did it change the list experience or? As you can see in my examples I tried the same through CSOM C# and both features weren't enabled so nothing happened. The option to enable new list experience is there, but you have to do it manually it seems. – Anders Nielsen Jul 28 '16 at 14:56
  • 2
    This governs the experience as a whole for the site or web. There a lot of quirks with the new experience that hamper some of our users, so we will kill it on a web or site basis. That's what this does. There is no API that has been exposed yet that allows you to change the behavior of a single library (and presumably list as that starts to roll out in the coming weeks). – Eric Alexander Jul 28 '16 at 15:02
  • This is no longer the correct answer. The answer from @Daniel Gimenez is now documented: msdn.microsoft.com/en-us/pnp_articles/… – Tom Resing May 24 '17 at 20:21
8

Greetings ...from the Future! You can now update the list in CSOM to disable and enable the New List Experience. The code below will update all the lists in site.

var lists = context.Web.Lists;
context.Load(lists, col => col.Include(l => l.ListExperienceOptions));
context.ExecuteQuery();
foreach (var list in lists)
{
    if (list.ListExperienceOptions != ListExperience.ClassicExperience)
    {
         list.ListExperienceOptions = ListExperience.ClassicExperience; 
         // list.ListExperienceOptions = ListExperience.NewExperience; 
         // list.ListExperienceOptions = ListExperience.Auto; 
         list.Update();
    }
}
context.ExecuteQuery();
0

To be clear, the future is not here, and there is no API available to update the list experience on individual lists. My customer has over a thousand sites where they absolutely want the new experience on libraries, but due to several bugs with the new experience on lists, for these they need the classic experience. To make matters worse, on a site template the list experience setting is ignored on sites created from the template. For my customer, not having an API option is painful, and a significant oversight.

  • 2
    If you are working on C# csom, they latest version of NuGet package does expose this property. But the SDK does not have it. – Asad Refai Jan 4 '17 at 10:57
0

You can do already do it using new libraries. This works for me:

  $lls=$ctx.Web.Lists
  $ctx.Load($lls)
  $ctx.ExecuteQuery()


  foreach($ll in $lls)
  {
   $ll.ListExperienceOptions = "NewExperience"
   $ll.Update()
   $ctx.ExecuteQuery()
  }

Excerpt taken from: https://gallery.technet.microsoft.com/SharePoint-Online-Set-all-3db41598

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.