I came into a situation where I wanted to use SharePoint Object Model SPSiteDataQuery to query data from Publishing Page.

However, I dont want the data query based on the permission on current login user, the query has to be query only the published version (last major version), regardless the permission of current login user.


login user is reader, contributor or full control, the query data should be only published version.

if the page is draft (0.1), no data will be query.

if the page is draft (1.1), data on version 1.0 will be query.

below is the sample code fragment on SPSiteDataQuery:

using(SPSite site = new SPSite("http://server"))
    using(SPWeb web = site.OpenWeb())
        SPSiteDataQuery query = new SPSiteDataQuery();

        query.Lists = "<Lists ServerTemplate=\"850\" />";
        query.Webs = "<Webs Scope='Recursive' />"; 
        query.ViewFields = "<FieldRef Name='Title' />";
        query.Query =  "<Where><Gt><FieldRef Name='ID' /><Value Type='Number'>0</Value></Gt></Where>";

         dt = web.GetSiteData(query);

my question is, can SPSiteDataQuery able to query only the published version of data?

perhaps query by View or any other property can help?

or change in CAML query able to achieve this?

any workaround on this?

thank you in advanced.

1 Answer 1


You may try adding following condition in the query:

<FieldRef Name=\"_Level\" /><Value Type=\"Integer\">1</Value>
  • This seems to filter an item being edited, but the query does not return its original version before being edited.
    – John_
    Dec 27, 2013 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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