I have a webpart with several CAML Querys that look like this:

SPSiteDataQuery qry = new SPSiteDataQuery();
qry.Lists = "<Lists ServerTemplate='104' Hidden='TRUE' />"; 
qry.Webs = "<Webs Scope='Recursive' />";
qry.ViewFields = "<FieldRef Name='Title' Nullable='TRUE' /><FieldRef Name='Author' /><FieldRef Name='Editor' /><FieldRef Name='Modified'/><FieldRef Name='Created'/>";
qry.RowLimit = 10;
qry.Query = "<OrderBy><FieldRef Name='Modified' Ascending='FALSE' /></OrderBy>";

return web.GetSiteData(qry);

With distincts ServerTemplates id for each query. They all are returning the same ViewFields.

The problem is that the execution of that can last more than 10 seconds. I would like to reduce this. Any idea how to do this? Is there any way to have an union of all CAML queries?

1 Answer 1


It looks like it isn't possible to include multiple ServerTemplates within one SpSiteDataQuery. Instead, you could try querying using ContentType.

For example:

// document libraries
qry.Lists = "<Lists BaseType=\"1\" />";
// ...
// code to query for "Document" or "Folder" content types
qry.Query = "<Where><Or><Eq><FieldRef Name="ContentType" /><Value Type="Text">Document</Value></Eq><Eq><FieldRef Name="ContentType" /><Value Type="Text">Folder</Value></Eq></Or></Where>";

Reference: Query multiple lists having different ServerTemplate with SpSiteDataQuery()

  • Thank you. It really worked. But the speed is still slow...
    – Bargant
    Oct 7, 2011 at 13:05
  • Are you still running multiple SPSiteDataQuery s? Did you specify multiple content types inside qry.Query? You may have to use search depending on how many things you are querying for.
    – Kit Menke
    Oct 7, 2011 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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