SPFileVersionCollection - why versions are sorted in mixed order?

Posted by Janis Veinbergs on Stack Overflow See other posts from Stack Overflow or by Janis Veinbergs
Published on 2010-02-26T10:16:54Z Indexed on 2010/03/18 7:31 UTC
Read the original article Hit count: 1181

SPFileVersionCollection and SPListItemVersionCollection versioning seems inconsistent to me. Inconsistency wouldn't be a problem to me, but sort order is.

SPListItemVersionCollection

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)

SPFileVersionCollection

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.

© Stack Overflow or respective owner

Related posts about sharepoint

Related posts about wss-3.0