Thursday, September 11, 2008

SharePoint: Root folder element not returned through SPList.GetItems(SPQuery)

Problem: a query like this

                SPQuery q = new SPQuery();
q.Query = "<Where><Eq><FieldRef Name='MyField'/><Value Type='Text'>ABC</Value></Eq></Where>";
q.ViewAttributes = "Scope=\"Recursive\"";
SPListItemCollection c = l.GetItems(q);
Console.WriteLine(c.Count);

on a list like with one element like

Folder, MyField='ABC'

was not returning the element.

Solution:

q.ViewAttributes = "Scope=\"RecursiveAll\"";

See here why ☺

No comments: