SPQuery Doesn't Search Sub Folders

If you are using the SharePoint object model to query a SharePoint list you will find out that SPQuery doesn't retrun items in the subfolders. In  order to execute a search query against a list and return results regardless of subfolder location you need to add "Scope='RecursiveAll'" attribute to the SPQuery object's ViewAttributes property.  Since the ViewAttributes property is a string you need to make sure that this attribute doesn't already exist.  If it exists you must remove it and then add it back to the ViewAttributes property.   

 

SPListItemCollection

foreach

(SPListItem item in itemCollection){
     //do something
}
SPQuery query = new SPQuery();
query.ViewAttributes += " Scope='RecursiveAll'";
itemCollection = list.GetItems(query);

Bookmark and Share

posted @ Thursday, October 30, 2008 10:14 PM

Print

Comments on this entry:

No comments posted yet.

Your comment:



 (will not be displayed)


 
 
 
Please add 5 and 8 and type the answer here:
 

Live Comment Preview:

 
«July»
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567