seanrco
seanrco

Reputation: 1079

CSOM File current version

I have a design requirement to show current File version. From what I can tell File object does not have a Version Number property and SharePoint basically does not consider current File state as a version? To get that work one would have to do the following I was thinking:

clientContext.Load(file, f => f.Versions);
FileVersionCollection fileVersionCollection = file.Versions;
int currentFileVersion = fileVersionCollection.Count + 1;

Right now I have File.Versions as on optional field to get initialized within a method. I wanted to keep optional so can omit if design does not need Versions in order to improve query performance. So if we cannot get current version from File obj directly want to call that out as design issue was thinking. However, if there is a way to get current version directly from File obj without initializing File.Versions please let me know (maybe I overlooked a field)? Thanks!

Upvotes: 0

Views: 940

Answers (1)

Michael Han
Michael Han

Reputation: 3655

No, there is no vesion property in File object. We have to initialize File.Versions to get the file version.

And to get current file version, we use FileVersion.IsCurrentVersion property to check it:https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee539266(v=office.15)

Below is an article for your reference:

https://www.codesharepoint.com/csom/get-current-version-of-file-in-sharepoint-using-csom

Upvotes: 1

Related Questions