开发者

CAML Query to select top level folders only

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 = st开发者_如何学运维ring.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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜