kwizcom banner advertisement

Disable "New Folder" in SharePoint Online Lists and Libraries

Requirement: Disable Folder Creation in SharePoint Online List or Document Library

How to Prevent Folder Creation in SharePoint Online?
To disable folder creation in SharePoint Online list or library,
  • Go to List or Library Settings >> Click on "Advanced Settings"
  • Under "Folders" section, set "No" for "Make 'New Folder' command available?"
    sharepoint online disable new folder
This disables "New Folder" option in SharePoint Online.

PowerShell to Prevent Folder Creation in SharePoint Online?
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Disable-SPONewFolder($SiteURL,$ListName)
{
    Try
    {
        #Get Credentials to connect
        $Cred= Get-Credential

        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #Get the List
        $List=$Ctx.Web.Lists.GetByTitle($ListName)

        #Disable "New Folder" 
        $List.EnableFolderCreation=$False

        #Apply the settings to list
        $List.Update()
        $Ctx.ExecuteQuery()

        Write-host -f Green "New Folder Disabled for the List '$ListName'!"
    }
    Catch {
        write-host -f Red "Error:" $_.Exception.Message
    }
}

#Set Parameters
$SiteURL="https://crescenttech.sharepoint.com"
$ListName="Team Projects"

Disable-SPONewFolder -SiteURL $SiteURL -ListName $ListName

Disable Folder Creation in SharePoint Online using PnP PowerShell:
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com"
$ListName = "Team Projects"

#Get Credentials to connect
$Cred = Get-Credential

Try {
    #Connect to PNP Online
    Connect-PnPOnline -Url $SiteURL -Credentials $Cred
    
    #Disable Folder Creation
    Set-PnPList -Identity $ListName -EnableFolderCreation $False
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
Disable "New Folder" in SharePoint Online Lists and Libraries Disable "New Folder" in SharePoint Online Lists and Libraries Reviewed by Salaudeen Rajack on April 28, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.