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 want to select the list of folders (without subfolders, not recursive) of a Document library using CrossListQueryCache.

Everything is working fine except that i am receiving ALL the folders and subfolders in the list and not just the first level of folders. what do i need to change in the code below so that only the first level of folders is returned without their subfolders and sub-subfolders etc...

string query = string.Empty; 
string websQuery = string.Format("<Webs Scope=\"{0}\"/>", "None"); 
string lists = "<Lists ServerTemplate=\"101\"" + " ><List ID=\"" + listid + "\" /></Lists>";   
bool useList = true; 
string relativeUrl = this.GetRelativeUrl(); 
query = string.Format("<Where><Eq><FieldRef Name='FSObjType' /><Value Type='LookUp'>1</Value></Eq></Where>", relativeUrl);   
CrossListQueryInfo info = new CrossListQueryInfo(); 
info.Lists = lists; 
info.Webs = websQuery; 
info.Query = query; 
info.ViewFields = "<FieldRef Name=\"FileLeafRef\"/>"; 
info.WebUrl = web.ServerRelativeUrl; 
CrossListQueryCache cache = new CrossListQueryCache(info); 
SiteDataResults sd = cache.GetSiteDataResults(site, true); 
share|improve this question
Even after FileDirRef and the List Name it din't work for me – user15530 Mar 13 '13 at 6:35

I really don't see a way you can do this...not with a CrossListQuery anyway. If you were doing this against a single list (i.e. SPList.GetItems(SPQuery) then you could add:

<Eq><FieldRef Name='FileDirRef'/><Value Type='Text'>"ListName"</Value></Eq>

and that would pull back only the top level folders, as the folders under that would have a FileDirRef of "ListName\TopLevelFolder" and so on.

share|improve this answer
Yeah, just don't include Scope="Recursive" like you normally would. – Kit Menke Aug 4 '11 at 19:11

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.