I've been creating a provider hosted app and I'm stuck at retrieving Documents titles using CSOM C# my code is as follows.
var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);
using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
Web web = clientContext.Web;
ClientOM.List list = clientContext.Web.Lists.GetByTitle("Documents");
clientContext.Load(list);
clientContext.ExecuteQuery();
Response.Write(list.Title);
Folder folder = list.RootFolder;
clientContext.Load(folder);
clientContext.ExecuteQuery();
string count = folder.ItemCount.ToString();
Response.Write("Folder variable count: "+count);
ClientOM.FileCollection fcollection = folder.Files;
clientContext.Load(folder.Files);
clientContext.ExecuteQuery();
Response.Write("\n Files count: " + folder.Files.Count);
foreach (ClientOM.File f in folder.Files)
{
Response.Write(f.Title);
}
}
Output : Folder variable count: 6 Files count: 0