4

I'm trying to access the properties (column/field metadata) from old file versions in a document library, via SharePoint's web API.

I can successfully query the library to get a list of files with their current versions using https://example.sharepoint.com/sites/[sitecollection]/_api/web/GetFolderByServerRelativeUrl('/sites/[sitecollection]/[libraryname]')/files, which exposes the URL for querying the file versions and file properties for each file in the library:

.../_api/web/GetFileByServerRelativeUrl('/sites/[sitecollection]/[libraryname]/[filename]')/Versions
.../_api/web/GetFileByServerRelativeUrl('/sites/[sitecollection]/[libraryname]/[filename]')/Properties

Unfortunately I can't find a way of getting the properties for a particular version of a given file. I've tried calling the Properties and ListItemAllFields endpoints for a file version (using both GetFileByServerRelativeUrl() and the _api/SP.FileVersione[guid] URL returned by the /Versions call), as well as providing the virtual location of the file version _vti_history/[version]/[libraryname]/[filename] as the argument for GetFileByServerRelativeUrl(), but all result in errors.

I've checked the SharePoint Files and Folders REST API documentation and there seems to be only a small subset of properties available for file versions, compared with normal files. Neither Properties nor ListItemAllFields are among them.

Where should I go from here?

1

As far as I see, neither the SPListItemVersion nor SPListItemVersionCollection object type are available in the client object model / web API interfaces.

I suggest you to use the good-old web services, like the Lists.GetVersionCollection method to access the required information from the client side.

For example (assuming you are using C# on the client side):

WSLists.Lists listService = new WSLists.Lists();
listService.UseDefaultCredentials = true;
XmlNode result = listService.GetVersionCollection(
    "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", "[ITEM ID]", "[FIELD NAME]");
string outerXml = result.OuterXml;

Further samples can be found here or here.

Alernatively, you could use the get document method of the FrontePage RPC Services, as described here, although that is even less trivial as the web service based approach.

  • This seems to be what I'm looking for. Is it possible to request multiple field values simultaneously using Lists.GetVersionCollection? I've tried including multiple <strFieldName> nodes in the SOAP request, but only the first value is returned. I have the field value I was originally after, but I don't know which version it comes from. – Jonathan Holvey Apr 28 '16 at 0:26
  • The first further samples link you provided indicates this isn't possible, and multiple requests to GetVersionCollection are required. – Jonathan Holvey Apr 28 '16 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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