Delete List (forget about forcedeletelist)
Okay - so I'm trying to test some import issues with lists and decide to export an existing list that has documents set the way I need them. I run my import test and realize I've got more work to do so I go to delete the list via the browser. Hmm... the delete option isn't there - no problem I say - there's a forcedeletelist command that I just blogged about last week so I'll use that. But what's this - I ran the command and I got this error: "The requested delete operation could not be performed. (Exception from HRESULT:0x800720CE)".
Okay - what the heck! What's the point of a "FORCE"deletelist command if it doesn't FORCE the deletion of the list. So I did some testing and I discovered that the reason it couldn't delete it was because there was a property called "AllowDeletion" which was set to false (my list was the "Documents" list which is part of the publishing feature so it's set to not allow deletion). I checked this property out and it turns out that it's a really simple property with public getter and setters (the later being unusual in my experience - I usually have to use reflection to hack the objects). So I set the property to true and then tried a simple SPList.Delete() and it worked like a charm.
So what did I conclude - forcedeletelist is misnamed and should be abandoned - I've created a new command called simply gl-deletelist which allows you to pass a "-force" parameter in to actually force the deletion of the list. Now granted - there may be cases in which mine still fails but at least it will handle the AllowDeletion setting! Here's the code:
1: internal static void Delete(SPList list, bool force, string url)
2: {
3: if (list == null)
4: throw new SPException("List not found.");
5:
6: if (!list.AllowDeletion && force)
7: {
8: list.AllowDeletion = true;
9: list.Update();
10: }
11: else if (!list.AllowDeletion)
12: throw new SPException("List cannot be deleted. Try using the '-force' parameter to force the delete.");
13:
14: try
15: {
16: list.Delete();
17: }
18: catch (Exception)
19: {
20: if (force)
21: {
22: using (SPSite site = new SPSite(url))
23: {
24: Utilities.RunStsAdmOperation(
25: string.Format(" -o forcedeletelist -url \"{0}\"",
26: site.MakeFullUrl(list.RootFolder.ServerRelativeUrl)), false);
27: }
28: }
29: }
30: }
C:\>stsadm -help gl-deletelist
stsadm -o gl-deletelist
Deletes a list.
Parameters:
-url <list view URL>
[-force]
Here's an example of how to delete a list passing in the force parameter:
stsadm –o gl-deletelist -url "http://intranet/Documents/Forms/AllItems.aspx" -force
Check out the books I've contributed to at Amazon.com:
January 30th, 2009 - 02:12
hi,
Great tool .
you saved my day.
keep up the good work.
regards,
swastik.
May 11th, 2009 - 10:58
I’m having this problem and would like to use your solution, but I don’t understand something. You provided the code to use to set the AllowDeletion to true, but where do I input and/or execute this code?
May 11th, 2009 - 12:21
Go to my downloads page (link at top of page) and download and install the WSP file. You can then use stsadm extension from there. The code posted is just for reference so people know what I’m doing with these extensions.
March 4th, 2010 - 13:59
Thank You Gary, this helped me out. You STSADM extensions are cool. Nice job!
Avinash Kota
http://sharepointreporter.wordpress.com
December 9th, 2010 - 02:31
I deleted the Document Library “Documents” from a Team Site (-force), now my navigation browse functionality is broken because it is looking for. Anything on fixing this issue?
December 11th, 2010 - 09:59
You could try adding the list back or otherwise reactivating the feature that creates it (I think it’s the team collab one). Beyond that I’d need you to further explain what is wrong with the navigation as I’m not really following.
August 9th, 2011 - 09:44
Great tools as always. Many thanks.
December 9th, 2011 - 10:06
hi thanks lot for putting this together, I have tried using this in our testing environment as we have a requirement to delete a corrupted list. Even with a properly working list the command mentioned above gives a command line error.
I have the syntax valid the help does list the command as the exteded command etc not sure why I am not able to delete the list.
December 9th, 2011 - 11:02
What’s the error? Are you on 2007 or 2010 and are you using the correct WSP?
February 8th, 2012 - 09:29
We had a problem where the Site Content and Structure view would not open, giving the error “An unexpected error has occured”. By increasing the verbosity of the ULS logs and looking up the Correlation ID we were able to find the GUID of the list which was causing the problem. I then looked up this GUID in the Content Database’s “AllLists” table (column tp_ID) to determine which list was the problem.
The lists were corrupted but could not be deleted using the above technique. This was returning the useless error message
“<nativehr>0×80070002</nativehr><nativestack></nativestack>”
We also tried deleting the lists using PowerShell but this returned an error saying “List does not exist. The page you selected contains a list that does not exist. It may have been deleted by another user.”
Finally we found that the list had previously been deleted and was already appearing in the Recycle Bin, but for some reason was also appearing in its original place in the SharePoint site.
So we deleted the item from the Site-collection level “Deleted from end user Recycle Bin” view, and the list then disappeared, and the Site Content and Structure view started working again.
Hope this might help someone!
February 20th, 2012 - 06:18
Thanks, your post helped me alot!
March 12th, 2012 - 14:53
Thanks Matt! This really had me stumped.
March 8th, 2012 - 05:35
Thanks Mathew. I wasted several hours trying everything I could think of before I found your post.
March 9th, 2012 - 07:47
Not sure who Mathew is but you’re welcome