Skip to main content

WSSV3FAQ

Go Search
Home
  
WSSV3FAQ > v3 WSS FAQ > Do you have code for deleting document versions earlier than a particular date?  

v3 WSS FAQ: Do you have code for deleting document versions earlier than a particular date?

Roman

III 

RomanNumber

Group

Administration 

Item

86 

Title

Do you have code for deleting document versions earlier than a particular date? 

Description

Raj M. posted this anonymously in the Windows Services newsgroup.
 
"Here are the exact steps for newbie.
 
1. Create the Windows Application or Console Application
2. Add the reference to Microsoft.SharePoint.dll
3. Copy the following code
 
using Microsoft.SharePoint;
SPSite site = new SPSite("http://localhost:9328");
SPWeb web = site.OpenWeb();
SPFolder myFolder = web.Folders["Shared Documents"];
 
//max versions to keep.
int maxVersions = 0;
foreach (SPFile myFile in myFolder.Files )
{
int nDocVersions = myFile.Versions.Count;
while ((maxVersions > 0) && (nDocVersions > (maxVersions - 1)))
{
myFile.Versions.Delete(0);
nDocVersions = myFile.Versions.Count;
}
}
4. Compile the code.
 
 
Thanks to Raj M. (if he objects to me quoting him, he should contact me)

Series

1-99 

Pr

 

OUT

 
Attachments
Created at 12/13/2008 1:53 AM  by Mike Walsh 
Last modified at 12/13/2008 1:53 AM  by Mike Walsh