1

I have used below code to get files in SharePoint. But using that code I am getting only files not folders. What I need is whole folder and documents in root directory. Please help me.

context.Credentials = new SP.SharePointOnlineCredentials(loginInfo.UserName, loginInfo.Password);
SP.List docList = context.Web.Lists.GetByTitle(loginInfo.DocumentLibraryName);
context.Load(docList);
SP.CamlQuery camlQuery = new SP.CamlQuery();
camlQuery.ViewXml = "<View Scope='RecursiveAll'></View>";
SP.ListItemCollection listItems = docList.GetItems(camlQuery);
context.Load(listItems);
context.ExecuteQuery();

1 Answer 1

0

if you want to get items in the root, you should not be using the scope attribute

listing documents, as well as folders, is something that the query should already be doing

so, according to your request, you can update as follows,

context.Credentials = new SP.SharePointOnlineCredentials(loginInfo.UserName, loginInfo.Password);
SP.List docList = context.Web.Lists.GetByTitle(loginInfo.DocumentLibraryName);
context.Load(docList);
SP.CamlQuery camlQuery = new SP.CamlQuery();
SP.ListItemCollection listItems = docList.GetItems(camlQuery);
context.Load(listItems);
context.ExecuteQuery();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.