I’ve wasted a lot of time this week. It’s unforunate because I’ve had a lot of work to do yet I spend a lot of time waiting for items in Sitecore to delete. Sometimes I have to wrestle with it, it keeps timing out and I keep telling the page to wait. Sometimes I try to load up a new tab but the whole site locks up. Eventually if it doesn’t come back alive I restart the app pool. Fun times.
So what’s the better way to handle this? It turns out it’s a convuluted one that is most effective. I would have thought a bit of custom code with a delete action would be the fastest way but from what I’ve discovered it’s not.
Start off by going into Content Editor
If you haven’t already, enable the Developer tool bar by right clicking the toolbar and checking off Developer
Next, in the navigation tree on the left find your way to the folder with lots of sub items you want to delete. In this example I am using /sitecore/templates/Common/BigFolder.
With BigFolder selected in the navigation tree you’ll want to go up to the Developer toolbar and click Serialize Tree.
This part may stil take a minute or two, but I promise you it will be faster and it wont time out. Once it is done you will find this folder in your file system, as what we’ve done is taken your item structure from the database and have created another representation of it as text files in your file system. For example look in C:\inetpub\wwwroot\YourWebsite\Data\Serialization\master\ with YourWebsite being the name of the Sitecore instance you are using. From there we will see a familiar structure representing your item tree. So for this example we used /sitecore/templates/Common/BigFolder so we should that same structure in here giving you C:\inetpub\wwwroot\YourWebsite\Data\Serialization\master\sitecore\templates\Common\BigFolder and then inside BigFolder you will see a file for every item you had in your tree. If you’ve used TDS you will be familiar with this Serialization process however if you are not don’t worry about it too much. Each record has been stored as a .item file which you could now in theory backup with WinZip or even push out in SVN or Git. But in our case we don’t want these files at all, so we’re going to delete them.
So why go through all this effort if we’re goign to delete them? Well we need to create the rest of the structure which happens when we serialize the whole tree. Now we can go in there, delete everything in this folder, then go back to Content Editor under our Developer toolbar and click Revert Tree. This will attempt to rebuild the tree from your selected item downward (so make sure you stil have /sitecore/templates/Common/BigFolder selected) and because it doesn’t see an item file it assumes this item should not exist and it deletes it from the database.
Fantastically this is faster than just deleting them through the right click menu, or even the DB Browser. Within a few seconds your screen will refresh and BigFolder will have no content in it. Even if moments before it had thousands of items under it. Woohoo!
A seasoned Senior Solutions Architect with 20 years of experience in technology design and implementation. Renowned for innovative solutions and strategic insights, he excels in driving complex projects to success. Outside work, he is a passionate fisherman and fish keeper, specializing in planted tanks.