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

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?

share|improve this question
up vote 1 down vote accepted

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()

share|improve this answer
Thank you. It really worked. But the speed is still slow... – Bargant Oct 7 '11 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 '11 at 13:27

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.