3

I've disabled versioning on a document library that has grown to 4GB in size for only around 900 documents. Although the versioning is no longer enabled the previous versions of the documents still exist in the AllDocStreams table in the content database. How do I get SharePoint to automatically release the space used by the no longer used versions of the documents?

I'd read somewhere that the unused documents are removed when the user next updates the document and SharePoint determines the previous versions are no longer required. However, I'd prefer to release the space immediately if possible.

2

Here are two solutions using PowerShell:
PowerShell Script to Delete All Versions in a Document Library
SharePoint PowerShell: Delete old versions of documents and items.

Essentially this should work (from first link):

$web = Get-SPWeb http://localhost
foreach ($list in $web.Lists)
{
  # examine if BaseType of list is NOT a Document Library
  if ($list.BaseType -ne "DocumentLibrary") 
  {
    # forget the rest and return to top
    continue
  }
  # loop through each item
  foreach ($item in $list.Items)
  {
    # work with the file object as we're in a document library
    $file = $item.File
    # delete all versions
    $file.Versions.DeleteAll()
  }
}
$web.Dispose();

I tested the $file.Versions.DeleteAll() and it worked for me

  • I have some event receivers attached to this list that I wouldn't want to fire. Would the "Versions.DeleteAll()" fire them? Also, does this only remove the previous versions and leave the current version in place? – Brian Scott Sep 18 '12 at 13:45
  • When I tested it did not delete my current version, but I strongly suggest you test this yourself! When it comes to firing the event I'm not sure. By the way, I just found this: sharepoint.stackexchange.com/questions/445/… seen it? – eirikb Sep 18 '12 at 13:48
  • It's DeleteAllMinorVersions ! – eirikb Sep 18 '12 at 13:50
  • Hi, it looks to me like DeleteAll() was the correct choice, this remove all current major versions other than the current live one. – Brian Scott Sep 19 '12 at 8:26
  • So my test was correct then, upated the answer yet again :) Thanks for validating – eirikb Sep 19 '12 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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