title: Retrieve All Documents from all Subfolders in a Document Library - CSOM
body: <p>I am using the client side object model approach C# in order to retrieve all list items from a document library containing sub folders.  I checked out the MSDN documentation and I am stuck as to why I cannot get the field property, or if I am even doing this right. </p>
  
  <pre><code>    NetworkCredential credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
              ClientContext clientcontext = new ClientContext(Resources.defaultSPSite);
              clientcontext.Credentials = credentials;
  
              //Load Libraries from SharePoint
              //Web site = clientcontext.Web;
              clientcontext.Load(clientcontext.Web.Lists);
              clientcontext.ExecuteQuery();
  
  
              //List sharedDocumentsList = clientcontext.Web.Lists.GetByTitle("TestLDOCS");
              //CamlQuery camlQuery = new CamlQuery();
              //camlQuery.ViewXml = @"&lt;View Scope='Recursive'&gt;&lt;Query&gt;&lt;/Query&gt;&lt;/View&gt;";
  
              foreach (List list in clientcontext.Web.Lists)
              {
                  clientcontext.Load(list);
                  clientcontext.ExecuteQuery();
                  //list.TemplateFeatureId.ToString().Equals("") &amp;&amp;
                      string baseType =  list.BaseType.ToString();
                      string listTitle = list.Title.ToString();
                      if (list.BaseType.ToString().Equals("DocumentLibrary", StringComparison.InvariantCultureIgnoreCase) &amp;&amp; list.Title.ToString().Equals("TestLDOCS", StringComparison.InvariantCultureIgnoreCase))
                      {
                          foreach (Folder subFolder in list.RootFolder.Folders)
                          {
                              foreach (File f in subFolder.Files)
                              {
                                  Console.WriteLine((string) f.Title);                     
                              }
                          }
                      }
               }
          }
  </code></pre>
  
  <p>The error that I am receiving is that the "foreach(File f in subFolder.Files)" collection may not be initialized error.  Is there anyway to get the field values of all documents in every subfolder within a document library using CSOM?</p>
  
  <p>I know you can strongly type the field values as well with a list item ie (listItem["fieldName"]).  Should I go this route instead?</p>