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)?
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;
}
}
Have a look into the U2U CAML Builder. If it can be done, this tool will allow you to build the query.
-
3-1 U2U CAML Builder is great tool but in this case is completely useless Commented Sep 11, 2011 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.