Sunday, October 25, 2009

Delete older versions of SharePoint list/library

Just to give you a brief background of why we developed this utility.

Suppose you have accidentally turned on the versioning feature in your document library and you are migrating data from Lotus Notes to SharePoint using any third party utility like Quest Notes migrator for SharePoint and assume you had to re-run the utility again and again on the version enabled document library so as to migrate notes data with full fidelity. What happens then? Many versions of the same document/list item get created.

Assume there are 4000 records which got properly migrated into the versioned enabled document library, but each record created many versions of the same item, as a result average size of each item went to somewhere around 400-500 MB and some of them items were also 1 GB in size.

The site was also deployed into Production. Clients encountered performance issues while accessing items in the document library since the size of the document library had sky rocketed.
What do you do in this case? How do you delete the unnecessary versions and retain only the latest version of the document/list item?

My utility will just do that for you, Delete Item Versions utility will delete older versions of the document library items, while retaining the most recent version of the same. Most of the times, the site is already deployed and running into the production environment, hence , we needed a utility, which can access our production site remotely from any local workstation without touching or deploying anything on the production environment.

We have tested this utility thoroughly and it works like a charm. It uses SharePoint web services and users can run it from their workstations provided they have access to that particular SharePoint webapplication.
We also plan to enhance the features of this utility. Here is a snapshot of the same:

Delete Item Versions
Snapshot of the Delete Item Versions utility
Click here to download the source code.

NOTE: You will have to change the webservice reference in the source code, Build the Project, Test the utility in your test environment and then use the DeleteItemVersions.exe for remotely deleting versions for your SharePoint List/Library.

Feel free to share your comments and ask me in case of any doubts.

I regularly post my SharePoint Insgihts at

You can also follow me on Twitter:


  1. HI Mehul,

    I downloaded your solution, but I cannot seem to get it to convert it using VS 2008.

    Can you post a solution that is VS 2008 compatible?


  2. Hi Ronaldo,

    Sounds strange, because the Solution is a Visual Studio 2008 solution itself.

    I can open it from my end and it does not ask for any conversion too. I also have the Re-sharper utility, can you try installing Re-Sharper in your envrionment.

    If you are trying to open it via Visual Studio 2005, then you can't, since it is a VS 2008 solution.

  3. Hi Mehul,

    I have finally gotten back to working with this again. Ok, I have re-installed VS2008, and I can compile the application.

    Here's my next question. I want to run this application from a test server, and delete the versions from the document libraries in the test server. The error that I get when I run the application is:
    Exception of type Microsoft.SharePoint.SoapServer.SoapServerExecution was thrown.
    Can you help?

  4. Hi Rolando,

    You need to modify the app.config file in the solution, change the URLS to your test envrionment urls and then go to Web Reference
    -> right click on SPLists -> Update Web Reference
    -> right click on SPVersions -> Update Web Reference

    It will start working...

  5. Hi Mehul,

    Ok, it still doesn't appear to work for me after making your last suggested changes.

    A few questions.

    1. I am trying to test this on a server that has MOSS2007 SP2,April cumulative update. Is this ok?
    2. Do I have to run this application remotely? Or can I just run it from the test server?
    3. Can I leave the view GUID field empty? I'm not sure what this should be set to.

  6. Additional debug information. I have added messages to the code to display after executing certain lines of code. The following code does not get executed, and is where I get an exception. So it appears that the code fails when the call to GetVersions is made.
    //Get Versions node for the current document
    XmlNode versions = VersionsService.GetVersions(node.Attributes["ows_EncodedAbsUrl"].Value);

    lblProgressMessage.Text = "After call to Get Versions.";

    Can you help?

  7. Hi Mehul,

    This removes the versions, but my Content Database is still as large as it ever was. Any ideas?


  8. James,

    I got the application to work. And if you didn't already know this, all deleted items are put in the recycle bin. So that may be why your content dbase is still large.

    btw, I'm trying to figure how to delete items from Folders in a doc library. It appears that this application does not iterate throught those items in a folder. Help!


  9. I figured it out! Here is the required code, that will return ALL items in a document library, including those in folders.

    System.Xml.XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");

    queryOptions.InnerXml = "";


  10. Sorry, the second line should contain:



  11. For some reason my cut/paste is not working!

    Go to:

    And look at the section that tells you that the ViewAttributes should be set to scope=Recursive in queryOptions.InnerXml

    Sorry about that- Rolando

  12. "Exception of type Microsoft.SharePoint.SoapServer.SoapServerExecution was thrown."

    Hi Rolando, how did you solve this problem?

    Cheers, Rick

    1. I was getting this error, too. Then I played with the rom limit field. I set it at 1000 and it still threw the exception. Set it at 500 and voila! It worked.

  13. Hi Mehul,
    I am getting an unauthorized execption!! Any idea why this is coming?

  14. anyone have a working compiled version i could d/l

  15. Works great! Just what I needed! Thank you Mehuil!