编程方式获取SharePoint 2010文档库中文件的版本

这段代码用于获取SharePoint 2010文档库中文件的版本,或者说是版本信息。该代码位于一个控制台应用程序中。

该代码假设你有一个文档库名为“Mydocumentlib”,其中至少包含了一个文档并启用了版本控制。下面的代码中外层的循环检查所有的文件,而内层的循环来获取每个文件的所有版本。

using (SPSite site = new SPSite(“http://SharePointSite”))
{
using (SPWeb web = site.OpenWeb())
{
SPList docs = web.Lists["Mydocumentlib"];

foreach (SPFile file in docs.RootFolder.Files)
{
Console.WriteLine(“File {0} has next version {1}. Version History:”, file.Url, file.UIVersionLabel);

foreach (SPFileVersion v in file.Versions.Cast().Reverse())
{
Console.WriteLine(” Version {0} checked in at {1} with this comment: ‘{2}’”, v.VersionLabel, v.Created, v.CheckInComment);
}
}
}}

参考资料

Programmatically get versions for files in sharepoint 2010 document library

posted @ 2010-09-06 21:12  Sunmoonfire  阅读(209)  评论(0)    收藏  举报