There is a code sample for this, a scheduled job that you can run:
Do a backup of the database before you start if anything goes wrong...
Per, I have tryed your code on a web site im perfecting and it doesn't work so good. The problem is that there are a LOT of page versions that I need to delete (around 25/page and over 5000 pages) I am working straight toward the database procedures now to try to make it more efficiently.
Do you have any suggestions or a script that could help me out?
I got the same trouble Diego, I´m having a lot of pages with a lot of versions and this job doesn't work.
In the recycle bin I have around 1000 pages and some of the pages in the recycle bin has more then 4000 page versions. All these pages makes the empty recycle bin job to fail every night.
All SQL query's from episerver support seems to stop to work when the site has to many pages with to many page versions. Even the store procedure editDeleteObsoletePageVersions fails when i use it directly in the sql server.
Right now I have built a rely slooooow job that deletes all old page versions in the recycle bin.
Its an recusive function that uses this method to delete the old versions.
PageVersionCollection versions = PageVersion.List(p.PageLink);
if (versions.Count > 1)
foreach (PageVersion version in versions)
if (version.ID != versions[versions.Count - 1].ID)
This function deletes on page version every sec. I'm not looking forward to doing this on all pages on the website.
i created the following script to minimize all page version too 5. Please note this was the first version of the script and alot of optomisation was done afterwards to it although cant seem to find the final version.
SET SET declare declare SELECT open fetch while BEGIN END close deallocate
declareNOCOUNT ON XACT_ABORT ON @pkID int;
fetchnext from page_cursor into @pkID
while@@FETCH_STATUS = 0
I am abouot to do a test-migration of a CMS4 site to CMS5, and one recommended action is to delete old versjons of pages before starting the migration tool. Since the migration tool parses each en every version of a page, having a large number of versioned pages will naturally slow down the migration process.
I have set the "max number of old versions" under System settings to a low number, but obviously that does not have any effect on versions already created.
My question is therefore: How to get rid of old versions for the entire site (or leave say, max 2 versions)?
I have posted this as a feature request, but if anyone have a good solution already, please respond to this post.