I have a task to restore Document Set to its latest snapshot. Since this functionality is implemented in event receiver, I use Server Side Object Model. By now, I have managed to restore the DS properties by updatingDS item, delete all document (file) versions higher that ones used in DS using SPFile.Versions.DeleteByID(id), but can not delete latest Document item versions. When I run
foreach(SPListItemVersion itemVer in file.Item.Versions)
if(double.Parse(itemVer.VersionLabel)> versionUsed) itemVer.Delete();
I get Microsoft.SharePoint.SPException: 'Cannot delete the current version'. I even saw an article that says you cannot delete current item version, so, you should restore previous version and then you would be able to delete it. But I managed to delete the file's version, but not item's. As far as I can see, this item version now has null value in FileVersion. Any idea on how to delete this item's version?