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?
SharePoint folders can be created on any list or library in where the "New Folder" option is turned ON. By default, folders are enabled in libraries and in lists they are disabled. Like folders in Windows Explorer, SharePoint Folders are used organize files. To disable folder creation in SharePoint 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:
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
}
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.