本文介绍了SPFileVersionCollection-为什么版本以混合顺序排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SPFileVersionCollection和SPListItemVersionCollection版本控制对我而言似乎不一致.不一致对我来说不是问题,但排序顺序是这样.

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

我可以理解ListItem的版本,因为它们以降序存储:

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

但是我不明白如何为文档库项目保存版本号:

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.

SharePoint团队是否有任何理由决定存储这样的SPFile版本?他们期望我编写自己的方法来获取最新版本吗?还是有内置的方法?

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?

注意:让我指出对于文档库项目,SPListItem.File不为null.

A note: Let me point out that SPListItem.File is not null for document library items.

推荐答案

我想在控制台应用程序中输出一些有关SPFileVersionCollection的信息,结果是:

Thought I would output some info about SPFileVersionCollection in console app and it turns out that:

  • 最后一个索引将保存当前(不是起草但已发布)版本(SPFileVersion.IsCurrentVersion属性对此是TRUE)
  • 0索引保存了最旧的版本
  • (最后一个索引-1)具有最后起草的版本(例如2.7),(最后一个索引-2)具有2.6等.
  • SPFile.Versions.Count = 0,如果您刚刚上传了全新的文档(发行前的次要版本).
  • 如果您继续上载新文档版本并且尚未发布,则它们将添加到SPFileVersionCollection,但是直到您发布一个文档时,IsCurrentVersion属性都未设置为true.
  • last index will hold the current (notdrafted but published) version(SPFileVersion.IsCurrentVersionproperty is TRUE for this)
  • 0 index holds the oldest version
  • (last index - 1) has the last drafted version (for example 2.7) and (last index - 2) holds 2.6 etc.
  • SPFile.Versions.Count = 0 if you just uploaded brand new document (minor version, before publishing).
  • If you continue uploading new document versions and have not yet published one, then they add to SPFileVersionCollection, however none has IsCurrentVersion property set to true until you publish one.

啊,我有一个错误的假设,那就是最新的文档草案版本应该算作最新版本.当然,最后发布的版本是最新版本!

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!

还是要当心矛盾之处.

这篇关于SPFileVersionCollection-为什么版本以混合顺序排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 18:41