I created a WCF service that uses Client-side Object Model (CSOM) to query file information from a SP Document Library.

I need to create a List<File> with all the files associated with all the versions for a given File stored in the Document Library. Is there a way through CSOM to get the File object of old versions of a file?

I found here! a solution for downloading an older version file, but what I need is the File object so I can access the Level property to know if the older version was also approved or not.

I'm doing the following:

List docList = context.Web.Lists.GetByTitle("Documents");

CamlQuery camlQuery = new CamlQuery();
ListItemCollection docCollection= listaDocs.GetItems(camlQuery);

foreach(var item in docCollection)
     var versionList = item.File.Versions;

     if(versionList != null)
          foreach (FileVersion version in versionList)
              // get version File object somehow
              // get version Level property somehow

I know that with Server-side I can access the desired info with:

SPFileVersionCollection versions = file.Versions;

foreach (SPFileVersion version in versions)
    int name = (int)version.File.Level;

But because I'm working in an external WCF, I'm using CSOM.

1 Answer 1


Make sure you also load the needed properties of the objects in your 'versionlist' and of the 'File' object.

    var file = context.Web.Lists.GetByTitle(listName).GetItemById(id).File;
    var versions = file.Versions;
    context.Load(file, f => f.ListItemAllFields, f => f.CheckOutType, f => f.UniqueId, f => f.Title, f => f.Name);

    context.Load(versions, vs=>vs.Include(v=>v.CreatedBy));

    for (int i = versions.Count; i > 0; i--)
       FileVersion version = file.Versions[i - 1];   
       string label = version.VersionLabel;
       string id = version.ID.ToString();
       string filename = Path.GetFileName(version.Url);
       string ext = Path.GetExtension(version.Url);
       string tmp1 = version.IsCurrentVersion;
       string tmp2 = version.Url;
  • 1
    Is it possible to get the values of the other columns of the list item, from older versions?
    – Flezcano
    Jul 28, 2017 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.