Murali Kris

Murali Kris

  • 1.4k
  • 253
  • 45.6k

how to loop the files from the documents folder

Jun 30 2020 6:11 AM
Hi mates,
 
how to loop files inside document folder
  1. string siteUrl = "https://Contoso.sharepoint.com/sites/EagleWipro";  
  2. string clientId = "de356957be31";  
  3. string clientSecret = "SI1UCNW2rrnHoow=";  
  4. using (var clientContext = new OfficeDevPnP.Core.AuthenticationManager().GetAppOnlyAuthenticatedContext(siteUrl, clientId, clientSecret))  
  5. {  
  6. try  
  7. {  
  8. Web oWebsite = clientContext.Web;  
  9. clientContext.Load(oWebsite);  
  10. clientContext.ExecuteQuery();  
  11. List targetlist = oWebsite.Lists.GetByTitle("Documents");  
  12. CamlQuery query = new CamlQuery();  
  13. query.FolderServerRelativeUrl = "/sites/EagleTest/Shared Documents";  
  14. ListItemCollection itemColl = targetlist.GetItems(query);  
  15. clientContext.Load(itemColl);  
  16. clientContext.Load(itemColl, d => d.Include(o => o["DisplayName"], o => o.File));  
  17. clientContext.ExecuteQuery();  
  18. foreach (ListItem listitem in itemColl)  
  19. {  
  20. Console.WriteLine(listitem.displayName);  
  21. }  
Here issue is itemColl returning count :0 infact files are there in the Documents folder
 
how to load files from Share Documents folder
 
Infact same code i tried with SPO authentication(userName/Password) its working fine, but as per requirement i tried ClientId, ClientSecreatID , but it returns Count 0.
 
your help would be highly appreciated

Answers (2)