SPFileVersionCollection and SPListItemVersionCollection versioning seems inconsistent to me. Inconsistency wouldn't be a problem to me, but sort order is.
I can understand versioning of ListItems as they are stored in descending order:
SPContext.Current.ListItem.Versions.Count -> 5
SPContext.Current.ListItem.Versions[0].VersionId -> 1026 (2.2 latest version)
SPContext.Current.ListItem.Versions[1].VersionId -> 1025 (2.1)
SPContext.Current.ListItem.Versions[2].VersionId -> 1024 (2.0)
... [4].VersionId -> (oldest version)
However I can't understand how version numbers are saved for a document library item:
SPContext.Current.ListItem.File.Versions.Count -> 4
SPContext.Current.ListItem.File.Versions[0].ID -> 512 (1.0 oldest one)
SPContext.Current.ListItem.File.Versions[1].ID -> 513 (1.1)
SPContext.Current.ListItem.File.Versions[2].ID -> 1025 (2.1 latest version)
SPContext.Current.ListItem.File.Versions[3].ID -> 1024 (2.0 (EDIT: IsCurrentVersion = True))
They are nor in ascending order, nor descending, but something mixed.
Is there any reason for SharePoint team to decide to store SPFile versions like that? And do they expect that I write my own method to get latest version or is there a builtin one for that?
A note: Let me point out that SPListItem.File is not null for document library items.
Thought I would output some info about SPFileVersionCollection in console app and it turns out that:
Ahh, i had a false assumption that a last document draft version should count as the latest one. Ofcourse, the last PUBLISHED version is the latest one!
Still, beware of inconsistency.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With