Enable new list experience on document library programmatically

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.

Replay

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()
    }
}

Category: sharepoint online Time: 2016-07-28 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 1.576 (s). 13 q(s)