Pages

Monday 6 January 2014

Programmatically view all file versions in a list

A very nice article by Anita about getting document versions:

SPDocumentLibrary sharedDocs = SPContext.Current.Web.Lists['Shared Documents'as SPDocumentLibrary;
resultBox.Text = string.Empty;
foreach (SPListItem doc in sharedDocs.Items)
{
     SPListItemVersionCollection coll = doc.Versions;
     resultBox.Text += 'Versions of  ' + doc.Name + Environment.NewLine;
     foreach (SPListItemVersion version in coll)
     {
          resultBox.Text += 'VersionLabel: ' + version.VersionLabel + ' IsCurrentVersion: ' + version.IsCurrentVersion + Environment.NewLine;
     }
}

And the result:


http://www.itidea.nl/index.php/documents-and-versioning

No comments:

Post a Comment