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);
Use SPQuery.ViewAttributes with "Scope" different from "Recursive":
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spquery.viewattributes.aspx
If you want to display only folders or NOT folders then you can add info about ContentType, like here (Drax's answer):
CAML queries: how to filter folders from result set?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With