Press "Enter" to skip to content

Office365 / SharePoint CSOM getting all list items content with Caml query

There is Office365/Sharepoint CSOM Caml query way to get all available list items even thay are in folders in particular list and also get the custom fields data with no need to specify the field internal names in the <ViewFields> part of the Caml query.

using (var clientContext = _context.CreateUserClientContextForSPHost())
                if (clientContext != null)
                    CamlQuery query = new CamlQuery();
                    query.ViewXml = 
                      @"<View Scope='RecursiveAll'>  
                               <Where><Eq><FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value></Eq></Where> 
                    var listItems = clientContext.Web.Lists.GetByTitle("Retention Rules").GetItems(query);

The key component here is 

<FieldRef Name='FSObjType' /><Value Type='Integer'>0</Value>

without it the query would not retrieve data for the custom fields.