SharePoint Online: “Delete this Document Library” is missing!
Problem: Cannot delete a SharePoint Online document library as the “Delete this Document Library” option is missing in document library settings!
I tried deleting the library from the site contents page, library’s ribbon menu, SharePoint Designer, Content and structure tool, Explorer view, and PowerShell, but none helped!
Solution:
You may not see the “Delete this list” option if you don’t have “Edit” or more access rights on the SharePoint Online site! Moreover, in some system libraries, the “Allow Deletion” flag is set to “FALSE” to prevent the library from accidental deletions. (E.g., in “Farm Templates”, “Style Library”, etc., delete this Document Library link is missing by default to prevent deletion).
How to enable delete in a SharePoint Online Document Library?
Use this PowerShell to enable Delete in a library by setting the “Allow Deletion” flag to True!
#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"
#Set parameter values
$SiteURL="https://Crescent.sharepoint.com/"
$LibraryName="AppAssets"
Try {
#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the Document Library and set allow deletion flag
$Library=$Ctx.Web.Lists.GetByTitle($LibraryName)
$Library.AllowDeletion = $True
$Library.Update()
$Ctx.ExecuteQuery()
#Delete the Document Library (Send to Recycle bin)
$Library.Recycle() | Out-Null
$Ctx.ExecuteQuery()
Write-Host "Document Library: '$LibraryName' has been Deleted Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Document Library!" $_.Exception.Message
}
The same thing can be achieved with PnP PowerShell:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/pmo"
$ListName = "Projects"
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the List
$List = Get-PnPList -Identity $ListName
#Enable Delete option for the list
$List.AllowDeletion = $True
$List.Update()
Invoke-PnPQuery
This enables deletion on the document library. To delete a document library in SharePoint Online using PowerShell, refer to my other post: SharePoint Online: PowerShell to Delete Document Library