Thursday, October 23, 2014

Programmatically Get List items inside the folders of SPList





How to search items inside the folders of list using caml query
many times while validating against multiple entries we have to query check , here we go to fetch all the  items inside the list including folders

you should use  spquery.ViewAttributes = "Scope=\"Recursive\"";  so that query searches in recursive way .
                             


full code
 SPList list = web.Lists["ListName"];


                                var querytext = "<View Scope='Recursive'><Where><Eq><FieldRef Name='UserName' /><Value Type='Text'>" + currentLogginUser.LoginName + "</Value></Eq></Where>";
                             
                                SPQuery spquery = new SPQuery();
                                spquery.Query = querytext;
                                spquery.ViewAttributes = "Scope=\"Recursive\""; 
                                var items = list.GetItems(spquery);