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'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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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

share|improve this answer
    
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
    
@Eirkib: Thanks, I'll check this out. –  Brian Scott Sep 18 '12 at 14:02
    
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
show 1 more comment

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.