Forum Discussion
luvsql
Mar 05, 2020Steel Contributor
Unable to Delete Default Document Library from Sharepoint Page
I've created a new page in SharePoint Online. I always create a NEW document library so they all have unique names. There is NO option to remove or delete the default one called Documents. Even though it's not on the page, it's still there in the SharePoint App and OneDrive App (click Libraries > page and it's still showing).
I've gone so far as to stop inheriting permissions and removed everything but it's still there for all users and causes lots of confusion. I've even had to rename it (DO NOT USE) yet it looks really bad when everyone sees that. It also shows in the Copy To and Move To areas of SharePoint for this page adding even more confusion.
Why can't it be removed on a page but it can on a classic site/subsite?
To clarify in Site Contents there is no remove option. In library settings, there is no delete.
luvsql then your site must be connected to an Office 365 Group. Sites that aren't connected to an Office 365 Group DO have the delete this Document Library link on the default Document Library as in my previous screenshot. All my sites which are not connected to an Office 365 Group DO have the link. Sites that are connected to an Office 365 Group do not.
Rob
Los Gallardos
Microsoft Power Automate Community Super User
- Gaurav GoyalBrass ContributorHi,
You can use following code to delete the library as well :
#Custom function to delete a SharePoint Online document library using powershell
Function Delete-SPODocumentLibrary
{
param
(
[string]$SiteURL = $(throw "Please Enter the Site URL!"),
[string]$LibraryName = $(throw "Please Enter the Library Name to Delete!")
)
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 #To permanently delete, call: $Library.DeleteObject()
$Ctx.ExecuteQuery()
Write-Host "Document Library: '$LibraryName' has been Deleted Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Deleting Document Library!" $_.Exception.Message
}
}
#Call the function to delete a document library
Delete-SPODocumentLibrary -SiteURL "https://mytenant.sharepoint.com/sites/Portal-Dev/" -LibraryName "Portal - Dev Documents" - RobElliottSilver Contributor
luvsql there is the Delete this document library option in the Library Settings page which will work on the default Documents Library and delete it:
Rob
Los Gallardos
Microsoft Power Automate Community Super User- luvsqlSteel Contributor
RobElliottThere is NO delete option. There is only a delete option on NEW document libraries, not the default.
- RobElliottSilver Contributor
luvsql then your site must be connected to an Office 365 Group. Sites that aren't connected to an Office 365 Group DO have the delete this Document Library link on the default Document Library as in my previous screenshot. All my sites which are not connected to an Office 365 Group DO have the link. Sites that are connected to an Office 365 Group do not.
Rob
Los Gallardos
Microsoft Power Automate Community Super User