Recently I have been asked about issue of retrieving old file versions from a SharePoint document library through server object model code, particulary check in comment for the major (published) versions. The first try was to retrieve data from the .Versions property of the SPListItem, or, from SPListItem.File.Versions, if we are talking about document libraries and files. And it worked – almost. The File.Versions property contains PREVIOUS file versions, and it does not hold the info on the current file version – this info is stored directly under the .File property. Here is a functioning piece of code to retrieve check in comment (or any other version information, for that matter), both for current and previous versions: using (SPSite site = new SPSite( "http://localhost" )) { using (SPWeb web = site.OpenWeb()) { SPList docsLis...
SharePoint Excellence is a community for Microsoft 365 professionals.