Delete List (forget about forcedeletelist)

Posted on Posted in SharePoint 2007, STSADM Commands

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.");
   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.");
  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: }

The syntax of the command can be seen below:

C:\>stsadm -help gl-deletelist

stsadm -o gl-deletelist

Deletes a list.

        -url <list view URL>

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

17 thoughts on “Delete List (forget about forcedeletelist)

  1. 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?

  2. 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.

  3. 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?

  4. 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.

  5. 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.

  6. 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

    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!

  7. Thanks Mathew. I wasted several hours trying everything I could think of before I found your post.

  8. Hi I have deleted from “Deleted from end user Recycle Bin” , still issue is there. Kindly suggest any other way to delete corrupted lists(List doesnot exists lists)

Comments are closed.