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

My scenario:

I have a page layout that has a user control on it. This user control queries data contained in other pages within the site collection to show a summary of related information. Anonymous uses do not have read access to the list containing the page data so I need to elevate privileges in order to read it. If I elevate by impersonating the site collection owner I'll get data from draft versions of items which I don't want. So, may question is, can I:

a) Impersonate the Contributor or Viewer privileges without having to create a fake user account and grant it permissions to the site, or

b) Can I write a CAML query that only returns data from the most recently approved (published) versions of each item, or

c) Is there some other strategy I could use that doesn't involve brute forcing my way through the versions of each item in the list using the API?


After weighing my options I decided to go with the first option. Creating a fake user account seemed to be the least messy and most efficient solution.

share|improve this question
up vote 4 down vote accepted

a) Not without creating a dummy user, no.

b) Yup, not that complex either, just need to check the SPListItem.Level property of each version of a file, and look for the Published level. See here for more info: Or here:

c) Don't think so. The Publishing infrastructure API is extremely flaky at best.

share|improve this answer
Thanks for the response. If no one comes up with something more elegant in the next couple days, I'll mark it as the answer. – Rob Windsor Aug 1 '11 at 19:08
For what it's worth I've looked into this fairly extensively too, using SP2013 Online. The dummy user approach appears to remain the only sensible one assuming you don't want to filter out versions where the latest version is unpublished (i.e. if the _level = 1 doesn't fit). – Timbo Feb 10 '15 at 9:14

I answered something similar to this the other day, as it relates to #2 anyway.

Creating Sharepoint Alerts only for published documents

...and don't be concerned that it doesn't have any upvotes or isn't marked as answered. I've used/tested this in the past, so I know it works. :)

Just add:

<FieldRef Name=\"_Level\" /><Value Type=\"Integer\">1</Value>

To your CAML query. Will only return published need to iterate through the the result.

share|improve this answer
Thanks for the answer, Rob. Unfortunately, it doesn't fit my scenario. I want a query that will return data from the last major version of each item. For example, if Item A is currently at version 3.2, I want version 3.0 to be returned in the result. – Rob Windsor Aug 1 '11 at 19:05

Why not use search? A keyword query would fetch the relevant data (as long as security is set correctly on default content query account)

share|improve this answer
Will the search API only return the data for published items for members of the Owners or Approvers group? – Rob Windsor Aug 1 '11 at 23:21
Not sure what you mean with the Owners or Approvers group, but it will never return drafts (unless elevation messes up something) – Anders Rask Aug 2 '11 at 12:03
+1 This does appear to be a viable option not listed in the accepted answer. It does involve a reasonable amount of search schema / managed property management, and would result in some content staleness while the search crawl takes place. – Timbo Feb 10 '15 at 9:17

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.