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, PowerShell but none of them helped!

Solution:

You may not see the “Delete this list” option if you don’t have “Edit” or more access rights on SharePoint Online site! Also, in some system libraries, “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 delete).

sharepoint online delete this document Library missing

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

#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 enabled deletion and deletes the document library. To delete a document library in SharePoint Online using PowerShell, refer my another post: SharePoint Online: PowerShell to Delete Document Library

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!

Leave a Reply

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