我有一個場景,我必須將SharePoint 2010列表(name =「VersionTestList」)中的所有數據移動到SQL Server數據庫。由於列表中啓用了版本控制,因此我也想移動以前的版本詳細信息。無論如何,我能夠移動最新的項目,但不幸的是我無法獲得以前的版本數據。我已經嘗試過使用客戶端對象模型並能夠獲取版本,但無法獲取相應版本的ListItem。請在下面找到我迄今爲止試過的代碼,並幫我解決這個問題。以編程方式使用客戶端對象模型獲取ListItemVersion SharePoint 2010
而且,這是我在列表項的版本是這樣的:
string path = web.ServerRelativeUrl + "/Lists/VersionTestTable/1_.000";
File file = web.GetFileByServerRelativeUrl(path);
clientContext.Load(file, item=>item.ListItemAllFields);
FileVersionCollection versions = file.Versions;
clientContext.Load(versions);
oldVersions = clientContext.LoadQuery(versions.Where(v => v != null));
clientContext.ExecuteQuery();
我的整個代碼是這樣的:
class Program
{
static void Main(string[] args)
{
GetVersionsUsingCOM();
}
public static void GetVersionsUsingCOM()
{
File file;
FileVersionCollection versions;
IEnumerable<Microsoft.SharePoint.Client.FileVersion> oldVersions;
ClientContext clientContext = new ClientContex("http://server:1200/test/Poc");
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQuery();
string path = web.ServerRelativeUrl + "/Lists/VersionTestTable/1_.000";
file = web.GetFileByServerRelativeUrl(path);
clientContext.Load(file, item=>item.ListItemAllFields);
//clientContext.ExecuteQuery();
versions = file.Versions;
clientContext.Load(versions);
oldVersions = clientContext.LoadQuery(versions.Where(v => v != null));
clientContext.ExecuteQuery();
if (oldVersions != null)
{
foreach (Microsoft.SharePoint.Client.FileVersion _version in oldVersions)
{
int count=0;
Console.WriteLine(_version.CheckInComment);
Console.WriteLine("Version : {0}", _version.VersionLabel);
//// Working fine till here but unable to get the version details from version.Url
string versionItemUrl = web.ServerRelativeUrl +"/" + _version.Url;
File oldFile = web.GetFileByServerRelativeUrl(versionItemUrl);
clientContext.Load(oldFile, f=>f.ListItemAllFields);
clientContext.ExecuteQuery();
Console.WriteLine(oldFile.ListItemAllFields["Name"]);
count++;
}
oldVersions = null;
}
Console.ReadLine();
}
}
Server對象模型類不提供嘗試利用客戶端對象模型時有太多幫助。 – 2013-11-11 13:33:12