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?

Would you like to disable the “New Folder” button in SharePoint Online lists and libraries? In this blog post, I will show you how to do just that. This can be helpful if you want to prevent users from creating new folders easily. Keep reading for step-by-step instructions.

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 lists. Like folders in Windows Explorer, SharePoint Folders are used to organize files. To disable folder creation in SharePoint list or library:

  1. Go to List or Library Settings >> Click on “Advanced Settings”.
  2. Under the “Folders” section, set “No” for the “Make ‘New Folder’ command available?”.
    sharepoint online disable new folder

This disables the “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://Crescent.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 the PnP PowerShell script.

#Config Variables
$SiteURL = "https://Crescent.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
}

In summary, By following these steps, you can quickly disable the ability for users to create new folders in SharePoint Online. This can be useful if you want to maintain a consistent folder structure or prevent users from cluttering up your document libraries. Remember that this change will affect all users who access this document library, so be sure to communicate the change to your team if necessary.

What is the difference between a library and a folder in SharePoint?

In SharePoint, a library is a container for documents, while a folder is a container within a library that can hold documents or other folders. Essentially, a library is a higher-level organizational structure that can contain multiple folders, while a folder is a sub-structure within a library. Additionally, libraries often have features such as version control, views, metadata, etc., while folders do not. In general, it is recommended to use libraries instead of folders in SharePoint for better organization, searchability, and security.

How do I delete a folder in SharePoint Online using PowerShell?

To delete a folder in SharePoint Online using PowerShell, Connect to your SharePoint Online site using the Connect-PnPOnline cmdlet and use the Remove-PnPFolder cmdlet to delete the folder. For example, the following PowerShell script deletes a folder named “Folder1” from a SharePoint Online site:
Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -Credentials (Get-Credential)
Remove-PnPFolder -Name “Folder1” -Folder “Shared Documents”
Note that you need to have to contribute permissions to the folder to delete it. Also, deleting a folder will also delete all the files and subfolders within it!
More info: Delete a folder in SharePoint Online with PowerShell

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

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

  • 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

Your email address will not be published. Required fields are marked *