I am trying to get the last major version of a file in a sharepoint-list by using CSOM with the following Code:

        var web = clientContext.Web;
        var list = web.Lists.GetByTitle("MyList");
        var listitem = list.GetItemById(id);
            x => x.File.ServerRelativeUrl,
            x => x.File.Versions,
            x => x.File.MajorVersion,
            x => x.File.MinorVersion

        ListItem oldItem = null;
        if (listitem.File.MinorVersion == 0)

            oldItem = listitem;
            foreach (FileVersion version in listitem.File.Versions)

                if (version.VersionLabel == listitem.File.MajorVersion.ToString() + ".0")
                    String versionUrl = listitem.File.ServerRelativeUrl + "?PageVersion=" + version.ID;
                    File versionFile = clientContext.Web.GetFileByServerRelativeUrl(versionUrl);
                    clientContext.Load(versionFile, f => f.ListItemAllFields);

                    oldItem = versionFile.ListItemAllFields;

If the current version is a major version, there is no problem to load the properties of the desired listItem. Unfortunately if the current version is a minor version the File.ListItemAllFields-Property does not contain any values. Does somebody know what i have to change to get the listItem of the last major version of a file if the current version is a minor one?

Thank you in advance.

1 Answer 1


The current version is the base URL, without the /_vti_history/nnn/ part of the URL. With respect to versions there is x Versions + 1 which is the current URL, not to be confused with the current published.

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.