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'm trying to use the SPSiteDataQuery to return the contents of several lists across a site collection. The problem I'm having, though, is that while there are only a few documents at the root level of these lists, the lists have folders containing large amounts of items, which causes the Query to exceed the List View Threshold.

I know that SPQuerys allow you to do something like

query.ViewAttributes = "Scope=\"Recursive\""

to recurse, and removing that will just show the results of the root folder only. Is there a way of filtering out ListItems that are in subfolders with any sort of CAML query?

share|improve this question
What level are you trying to stop returning values at? Direct subfolders of the root folder? (ie: Root/Folder/Document.doc) Or subfolders of folders directly beneath the root? (ie: Root/Folder/Subfolder/Document.doc) – RJ Cuthbertson Jan 22 '13 at 21:00
Direct subfolders and their subfolders - the goal is to only have list items in the root folder being returned. – user14330 Jan 22 '13 at 21:04
OK, I thought about this for a minute to come up with the best answer I can. There is no way to filter this via a property with the SPSiteDataQuery. Your best bet is to try to refine your query more to return less items. – RJ Cuthbertson Jan 22 '13 at 21:25
Alright, thank you. I guess then it'd be possible to perform multiple SPQueries, but I'm not sure if that's reasonable or feasible. – user14330 Jan 22 '13 at 21:32
As long as you aren't querying across site collections that is a viable option. Just use another collection like List<SPListItem> and add the result sets. – RJ Cuthbertson Jan 22 '13 at 21:35

Your Answer


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

Browse other questions tagged or ask your own question.