1

我正在尝试将 sharepoint Foundation 2010 用作网站的文件存储。每个文档更新都必须经过一个批准周期,最终达到批准状态以显示在最终用户的网站上。在 sharepoint 中更新文档时,即使先前的版本已获得批准,状态也会重置为“草稿”。这是预期的行为。

File.Versions 给了我版本列表。

如何获得上次“批准”的版本?

4

1 回答 1

1

您将需要遍历 ListItem 的版本并找到已发布的最新版本。使用SPListItemVersionCollection循环浏览版本并检查SPFileLevel

根据Sebastian Wojciechowski对SPListItemVersionCollection上 MSDN 文章的社区补充

SPListItem.Versions[0] //this is current version of the item
SPListItem.Versions[1] //this is previous version of the item
SPListItem.Versions[SPListItem.Versions.Count - 1] //this is first version of the item

版本以相反的顺序(从最新到最旧)索引,因此您的代码将类似于:

// Retrieve all versions
SPListItemVersionCollection itemVersions = item.Versions;
for (int i = 0; i < itemVersions.Count - 1; i++)
{
    // Check if version is published
    if (itemVersions[i].Level == SPFileLevel.Published)
    {
        return itemVersions[i];
    }
}
于 2012-04-24T17:26:58.547 回答