I have some code which I am attempting to use to "rollback" a SharePoint document and it's metadata properties to a previous version using ootb version control and the SharePoint API. Here is a sample of my code:

int versionCount = item.Versions.Count;
if (versionCount > 0)
 // this only restores properties

The expected result of calling restore using 1 (the newest version before the current version) would be to restore the file and metadata. Instead, only the metadata is restored and the current file is copied to the new "restored" version.

Furthermore, I have attempted to use item.File.Versions only to find item.File.Versions.Count is 1.

Can anyone provide any insight?


make sure that you use the SPFile object to get the Versions property from like below. Restoring an SPListItem will only restore the metadata not the binary document.

SPListItem item = ...
SPFile file = item.File;
int versionCount = file.Versions.Count;
if (versionCount > 0){ 

Cheers /WW

  • The item.File.Versions collection only contains the current version even though the version page is showing the current (2.0) and previous (1.0) versions. Jan 20 '10 at 17:16
  • @Dylan Is your version 2 checked in? I'm not sure, but I would guess there is an alternate API method to retreive drafts if Wictor's code doesn't access them.
    – Tom Resing
    Feb 4 '10 at 15:07

I have found that restoring a previous version will create a new version with information from the 'selected' version. It will not 'restore' and delete the 'current' version. IE: Version 1 Version 2 Version 3

If you restore version 1, it will become version 4, all 4 version will be available afterwards.

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.