A while back, I wrote a console application that helped me cleanup file versions in a publishing site collection just before we went live with the site. This console application was sitting on my laptop for the longest time till now. This application evolved into an STSADM Extension. This blog entry represents the work done prior to that, sorry 😦 Hopefully in the near future, I can try to write it in PowerShell and post it back here.
Disclaimer
BIG disclaimer here. What I am trying to describe here in this post falls in a time period before MOSS SP1. Code is not 100% clean. Code is not rock solid. Please feel free to provide feedback.
Problem
The problem was simply to try to delete and recycle all file/page versions just prior to site go live. We didn’t want to keep old versions of files that we don’t need and take up space in the database. The other part of the problem, is simply forgetting or not planning for version control. A bunch of libraries in a MOSS 2007 publishing site come (by default) with versioning enabled, but not necessarily configured. We didn’t configure version control prior to content authoring.
Solution
This code tries to connect to the site collection in question after validating it, iterates through its sub sites and clean up file versions.
<Code>Was removed due to it’s ugliness… I will repost later.</Code>
Usage
Say you compiled the above code snippet successfully, you should be able to do something like this:
RecycleOrDeleteFiles.exe -o recycleall -url http://sharepoint -folders pages,sitecollectionimages,_catalogs -includesubfolders
Resources
Some resources that were used to develop this solution:
SPFile – http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfile.versions.aspx
SPFolder – http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.aspx
SPFarm – http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spfarm.aspx
Leave a comment