Reputation: 4959
i have a list in SharePoint 2010 that has fields "title,count" .one of the fields (count) possible to change.
i want to access the last version of this property. by this article: but there are no accepted answer yet.
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;
here i can access to properties but "count" doesn't exist here.
i want to have differences by last versions like SharePoint
i have other method (find it here ) that return for me those last property values
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
}
error here
An error has occurred.","ExceptionMessage":"Value does not fall within the expected range
is there any solution shorter than this for retrieve all last values of specific field?
Upvotes: 1
Views: 2384
Reputation: 46
Sadly actual version data is not available from CSOM. You can get the data by extracting it from /_layouts/Versions.aspx?list={[THE LIST ID]}&ID=[THE ITEMID]&IsDlg=1;
I used HTMLAgilityPack to parse out the data I was looking for (a past value for a specific field)
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(DownloadedPageContent);
HtmlNodeCollection n = doc.DocumentNode.SelectNodes("//tr[@id='vv" + VersionId + FieldName +"']/td");
String value = n[1].InnerText.Trim();
Upvotes: 3