如何返回更改的版本和访问属性之间的差异?

时间:2014-03-15 16:46:58

标签: c# sharepoint-2010 csom splistitem

我在SharePoint 2010中有一个列表,其中包含“title,count”字段。字段(count)可能会更改。

我想访问此属性的最新版本。通过这个article:但还没有接受答案。

            File file;
            FileVersionCollection versions;
            ClientContext clientContext;
            IEnumerable<Microsoft.SharePoint.Client.FileVersion> oldVersions;

            clientContext = new ClientContext(siteUrl);
            clientContext.Credentials = new NetworkCredential(user, password, shp.domainname);
            Web web = clientContext.Web;
            clientContext.Load(web);
            clientContext.ExecuteQuery();

            string path = web.ServerRelativeUrl + "/Lists/" + listname + "/" + id1 + "_.000";  // it represet list id 7
            file = web.GetFileByServerRelativeUrl(path);

            ListItem versionListItem = file.ListItemAllFields;

            clientContext.Load(versionListItem);
            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)
                {
                     DateTime date = new DateTime();
                     date = _version.Created.Date;

这里我可以访问属性,但这里不存在“count”。

我希望像SharePoint这样的最新版本存在差异

sharepoint 2010 show version history and diffrences

我有其他方法(找到它here),它返回给我最后一个属性值

  ClientContext clientContext = new ClientContext("http://basesmc2008");
  Web site = clientContext.Web;
  clientContext.Load(site);
  clientContext.ExecuteQuery();

  File file = site.GetFileByServerRelativeUrl("/Shared Documents/test.tif");
  clientContext.Load(file);
  clientContext.ExecuteQuery();

  ListItem currentItem = file.ListItemAllFields;
  clientContext.Load(currentItem);
  clientContext.ExecuteQuery();


  FileVersionCollection versions = file.Versions;
  IEnumerable<FileVersion> oldVersions = clientContext.LoadQuery(versions.Where(v => v.VersionLabel == "1.0"));
  clientContext.ExecuteQuery();


  if (oldVersions != null)
  {
  foreach (FileVersion oldFileVersion in oldVersions)
  {


     File oldFile = site.GetFileByServerRelativeUrl("/" + oldFileVersion.Url);
     clientContext.Load(oldFile);
     clientContext.ExecuteQuery();

     ListItem oldItem = oldFile.ListItemAllFields;
     clientContext.Load(oldItem);
     clientContext.ExecuteQuery();         
     //error here
  }

错误

  

发生错误。“,”ExceptionMessage“:”值不在其中   预期范围

有没有比此更短的解决方案来检索特定字段的所有最后值?

1 个答案:

答案 0 :(得分:1)

可悲的是,CSOM无法提供实际版本数据。您可以通过从 / _ layouts / Versions.aspx?list = {[THE LIST ID]}&amp; ID = [THE ITEMID]&amp; IsDlg = 1 ;

中提取数据来获取数据

我使用HTMLAgilityPack来解析我正在寻找的数据(特定字段的过去值)

HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(DownloadedPageContent);

HtmlNodeCollection n = doc.DocumentNode.SelectNodes("//tr[@id='vv" + VersionId + FieldName +"']/td");

String value = n[1].InnerText.Trim();