Question

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.

Was it helpful?

Solution 4

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.

OTHER TIPS

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

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top