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?

Folders can be created on any SharePoint list or library where the “New Folder” option is turned ON. By default, folders are enabled in libraries, and in lists. Like folders in Windows Explorer, SharePoint Folders are used to organize files. To disable folder creation in SharePoint list or library:

  • Go to List or Library Settings >> Click on “Advanced Settings”
  • Under the “Folders” section, set “No” for the “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

To disable folders in SharePoint Online, use this PowerShell:

#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:

Let’s restrict folder creation in SharePoint Online using PnP PowerShell script.

#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
}

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

One thought on “Disable “New Folder” in SharePoint Online Lists and Libraries

  • November 5, 2020 at 5:15 PM

    ok so this will block people creating a new folder but is it site wide or just the current folder and does it stop people from creating a folder via onedrive file explorer

    Reply

Leave a Reply