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

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?

Edit:

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

3 Answers 3

up vote 3 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: http://mysharepointwork.blogspot.com/2011/03/get-published-version-of-list-item.html Or here: http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/a8ce6143-43cb-4c25-9e9e-b135e8b5014f.

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

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 items...no need to iterate through the the result.

share|improve this answer
1  
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

Your Answer

 
discard

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.