Skip to main content
Updated Answer
Source Link
Hardik
  • 7.7k
  • 2
  • 19
  • 37

UPDATED

Please replace below code

File f = web.GetFileByServerRelativeUrl("/"+_version.Url.ToString());

with

string versionItemUrl = file.ServerRelativeUrl.Replace(Path.GetFileName(file.ServerRelativeUrl),"") + _version.Url;
File oldFile = web.GetFileByServerRelativeUrl(versionItemUrl);

& try again.

UPDATED

Please replace below code

File f = web.GetFileByServerRelativeUrl("/"+_version.Url.ToString());

with

string versionItemUrl = file.ServerRelativeUrl.Replace(Path.GetFileName(file.ServerRelativeUrl),"") + _version.Url;
File oldFile = web.GetFileByServerRelativeUrl(versionItemUrl);

& try again.

Source Link
Hardik
  • 7.7k
  • 2
  • 19
  • 37

You can use below mentioned code to get the details version of specific item from SharePoint list using Client Object Model.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Net;

namespace AccessVersionItems
{
    class Class1
    {
        File file;
        FileVersionCollection versions;
        ClientContext clientContext;
        IEnumerable<Microsoft.SharePoint.Client.FileVersion> oldVersions;
        public void GetVersion()
        {
            clientContext = new ClientContext("http://xxxxxxx/workspace");
            clientContext.Credentials = new NetworkCredential("aaaa", "bbbbbb");
            Web web = clientContext.Web;
            clientContext.Load(web);
            clientContext.ExecuteQuery();

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

                    ListItem versionListItem = file.ListItemAllFields;file.ListItemAllFields.FieldValues["Defect_x0020_Name"]
                    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)
                        {
                           
                            Console.WriteLine("Version : {0}", _version.VersionLabel);  // till working fine
                          
                            
                            File f = web.GetFileByServerRelativeUrl("/"+_version.Url.ToString());
                            clientContext.Load(f, ff => ff.ListItemAllFields);
                            clientContext.ExecuteQuery();
                            string a = "";
                        }
                    }
                    Console.ReadKey();
                }
    }
}

Note:-

Please change all server & list details (in variables) according to your server