Monday, 7 July 2014

Delete SharePoint List/Library when Remove/Delete option is missing.

This week I received a question from one of our customers and decided to share the solution because you can find it useful if you get into similar situation like mine. The background story is that this customer is using SharePoint 2013 for their intranet. They have custom solution with two site definitions(templates) that solves two different business needs.
The reported issue was that on the sites created with one of the definitions the users are able to delete 'Documents' library, but on the sites with the second definition the users are unable to do so. The Remove button is missing, like the picture below.


Both sites come with 'Documents' library when they are created.
I did some investigation and found that the library in the first template comes from the site definition. The site is designed to be deployed with such library. In the second template where the user cannot delete the library it comes from the web level feature 'SharePoint Server Publishing' that is activated in the RootWeb, this is also by definition design. You can also see this in the description of the library. Along with this library the 'SharePoint Server Publishing' feature creates some important lists and libraries like 'Pages' and 'Workflow Tasks' and couple more. By default this lists and libraries cannot be deleted, this is why the 'Remove' option is missing.
The ability a SharePoint list (lists and libraries are same object in SharePoint OM) to be removable or not depends by the value of property of the SPList object called AllowDeletion. If the value is True the list can be deleted if it is False you cannot delete it.
I explained this to the customer, but they required to have the ability to delete this particular library from the site in question. Luckily we can set the value of AllowDeletion in existing List or Library.
Be very careful when you delete such lists it can break your site! But in my case I decided that if the library is not used by the users or for site assets I can safely delete the 'Documents' library from one of the sites. Below is the PowerShell script I used to change the value of AllowDeletion property.


$web = Get-SPWeb('http://publish.auto.l/')

$list = $web.Lists['Documents']

$list.AllowDeletion = $true

$list.Update()


After this the Remove/Delete options are available in their usual locations Site Content, Content and structure, ..etc.



No comments:

Post a Comment