title: Creating List in Sharepoint takes ages
body: <p>I try to clear a very big list in Sharepoint. Because of Sharepoints slow deleting-mechanism I decided to save a template (without data) from that list, delete that list and then create a new list from that template. The code of that is below:</p>
  
  <pre><code>public static void TruncateList(SPList list)
  {
     SPSecurity.RunWithElevatedPrivileges(delegate()
     {
        using (SPSite site = new SPSite(list.ParentWeb.Site.ID))
        {
           using (SPWeb web = site.OpenWeb())
           {            
                 web.AllowUnsafeUpdates = true;
                 SPList listCopy = web.Lists[list.ID];
                 string title = listCopy.Title;
                 string description = listCopy.Description;
                 string backupName = string.Format("BACKUP_{0}", title);
  
                 // Delete old Template if exists:
                 SPList gallery = web.Lists["List Template Gallery"];
                 foreach (SPListItem item in gallery.Items)
                 {
                    if (item.Title == backupName)
                    {
                       item.Delete();
                       break;
                    }
                 }
  
                 // Save Template:
                 listCopy.SaveAsTemplate(backupName, backupName, string.Empty, false);
  
                 // Load Template:
                 SPListTemplate template = web.Site.GetCustomListTemplates(web)[backupName];
                 template = web.ListTemplates[backupName];
  
                 // Delete List:
                 listCopy.Delete();   
  
                 // Add empty List from Template:   [HANGS HERE!]                                                        
                 web.Lists.Add(title, description, template);
  
                 web.Update();
                 web.AllowUnsafeUpdates = false;
           }
           );
          }
      }
  }
  </code></pre>
  
  <p>Saving the template works fine as well as deleting the original list (listCopy.Delete()) which takes a while</p>
  
  <p>But when trying to create that List again (web.Lists.Add) the server got stuck until it gets a Timeout-Exception after some minutes.</p>
  
  <p>Useful to mention: This is my developer machine. Noone but me is accessing that web/List</p>