SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying find exact CAML query, or other possible way in code to find out "The last major published version" (not necessarily the latest)?

share|improve this question

Note: File can have multiple major versions but only one version can be published one!

You cannot get published version by using CAML query. To do it by code you need something like this:

// item is SPListItem object retrived by CAML query or some other method
// there also some other options on how to get SPFile
SPFile file = item.File;

for (int i = file.Versions.Count - 1; i >= 0; i--)
     //check if version level is Published
     if (file.Versions[i].Level == SPFileLevel.Published)
          //get published version label eg. 2.0
          string publishedVer = file.Versions[i].VersionLabel;

          // get conent of published version (if needed)
          byte[] bytes = file.Versions[i].OpenBinary();

share|improve this answer

Have a look into the U2U CAML Builder. If it can be done, this tool will allow you to build the query.

share|improve this answer
-1 U2U CAML Builder is great tool but in this case is completely useless – Vedran Rasol Sep 11 '11 at 22:55

Unfortunately CAML doesn't allow you to retrieve a specific version of the document/List Item. You would have to use the API to do this.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.