Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Very Large List (~5000 documents) which has been chugging along for about a year. It has had versioning turned on, with major versions, keeping 2 old versions. We're totally restructuring the Document Library (more on that in another question) and I'd like to simply get rid of the old versions across the board to clean up the library and regain space.

I've turned versioning off, but the versions don't go away, when I think they should. Any thoughts? One thing it's important to note is that I inherited the Document Library. It is a little odd in several ways and I'm not exactly sure how it was created.

share|improve this question
    
From the answers below (thanks, all!), it's clear that there is no easy answer to this one. Each of the suggestions has a drawback of some sort (you lose the document ownership, etc.), but does address at least part of the issue. It really becomes a problem when disk quotas are in play! Too bad there isn't a simple "purge versions" method for a Document Library. –  Marc D Anderson Jan 11 '10 at 14:08

4 Answers 4

Unfortunately I cannot think of a non-programmatic way of doing this, I had a quick look at this and have created some sample code to loop through and delete the versions except for the latest one (this relies on the latest version being published though):

 using (SPSite site = new SPSite("http://yourserver/sites/site"))
        {
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists["Test Doc Library"];
                foreach (SPListItem item in list.Items)
                {
                    SPListItemVersionCollection versionCol = item.Versions;
                    int count = versionCol.Count;
                    int j = 0;
                    for (int i = 1; i < count; i++)
                    {
                        if (versionCol[i].VersionId != versionCol[j].VersionId)
                        {
                            SPListItemVersion version = versionCol[i];
                            version.Delete();
                            count = item.Versions.Count;
                        }
                    }
                }



            }
        }

However the code runs through fine but the version doesn't actually disappear properly, I think you will have to do something with the SPFileVersion collection also as it is a document library. This should get you started anyhow, let me know how you get on.

Cheers

share|improve this answer

Not sure if there is a way to write to the created/createdby fields using the web services, but you could write an export app (for both binary data + metadata) that uses the web services and saves everything to your local machine. Also write an import app which uploads the files into a new doclib (could upload into separate folders, solving the issue raised in your other question) and re-applies the metadata.

share|improve this answer

If for example you have 100 versions of a document and then restrict versioning to last 2 versions, the previous 98 wont go away Except when you insert a new version.

A simple way to clean up these old versions of each document in the library is to export the content of the subsite (stsadm export works on the site level not library level) with the versions parameter =1 to only export the last version. You can then delete this site and import it back and thus get rid of all the earlier versions. stsadm export documentation can be found here (http://technet.microsoft.com/en-us/library/cc262759.aspx )

Another option (simply a variation of the above) is to use the content deployment wizard (http://spdeploymentwizard.codeplex.com/ ), you will need to export the doc library without versions, then delete existing and import it back in.

share|improve this answer
up vote 1 down vote accepted

Now that I'm older and a teeny bit wiser, I would have solved this by writing client-side script. Using SPServices, I could have looped through all of the items in the Document Library and called DeleteAllVersions for each. That's the "no code" way to write code to do it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.