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");
context.Load(docList);
context.Load(docList.RootFolder);
context.Load(docList.RootFolder.Folders);
context.ExecuteQuery();
CamlQuery camlQuery = new CamlQuery();
ListItemCollection docCollection= listaDocs.GetItems(camlQuery);
context.Load(docCollection);
context.ExecuteQuery();
foreach(var item in docCollection)
{
context.Load(item.File);
var versionList = item.File.Versions;
context.Load(versionList);
context.ExecuteQuery();
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.