Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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
add comment

3 Answers

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();

          break;
     }
 }
share|improve this answer
add comment

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
2  
-1 U2U CAML Builder is great tool but in this case is completely useless –  Vedran Rasol Sep 11 '11 at 22:55
add comment

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
add comment

Your Answer

 
discard

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