CSOM Retrieving ListItemCollection is empty

Copper Contributor

Hello everyone,


I have tried to make a simple console application that retrieves list items from Share Point Online. It works fine when I retrieve list of the sites or list titles from the site, but I receive no list items when I try to get it from the particular list. Source list contains less then 50 items and this list was made by using "GenericList" template ("CustomList", ListTemplateId=100).

I've listed many examples of similar tasks and almost all of them were written in the same way. That's why I don't exclude that thet reason of my case might be in an insufficient permissions (I attach a screenshot of the API permissions).

Also I checked that item-level permissions is set to "1" - allow user read all items.

Please, check my code and app permissions. Any help will be highly appreciated.




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using SP = Microsoft.SharePoint.Client;

namespace SharePointTrigger
    class Program
        static async Task Main(string[] args)
            Uri site = new Uri("https://MyCompany.sharepoint.com/sites/MyProject");
            string user = $"ServiceUser@MyCompany.com";
            string rawPassword = $"password";
            SecureString password = new SecureString();
            foreach (char c in rawPassword) password.AppendChar(c);

            using (var authenticationManager = new AuthenticationManager()) //HELPER CLASS TO OBTAIN ACCESS TOKEN
            using (var context = authenticationManager.GetContext(site, user, password))

                Web web = context.Web;
                lists => lists.Include(list => list.Title,
                                    list => list.Id));


                foreach (SP.List list in web.Lists)

                //RETRIVING LIST ITEM
                Web myWeb = context.Web;
                SP.List myList = myWeb.Lists.GetByTitle("List_of_Items");

                SP.ListItemCollection listItemCollection = myList.GetItems(CamlQuery.CreateAllItemsQuery());

                            eachItem => eachItem.Include(
                                                        item => item,
                                                        item => item["Title"],
                                                        item => item["ID"]


                foreach (SP.ListItem listItem in listItemCollection)
                    Console.WriteLine("ID: " + listItem["ID"].ToString() + "Title: " + (string)listItem["Title"].ToString());










1 Reply

I am encountering the exact same issue and have been grappling with it for the past two days. I would greatly appreciate any leads or suggestions that could help me resolve this problem.