User Profile
MikhailLazutkin
Copper Contributor
Joined Oct 27, 2020
User Widgets
Recent Discussions
CSOM Retrieving ListItemCollection is empty
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)) { //RETRIVING LIST TITLE - WORKS FINE /* Web web = context.Web; context.Load(web.Lists, lists => lists.Include(list => list.Title, list => list.Id)); context.ExecuteQuery(); foreach (SP.List list in web.Lists) { Console.WriteLine(list.Title); } */ //RETRIVING LIST ITEM Web myWeb = context.Web; SP.List myList = myWeb.Lists.GetByTitle("List_of_Items"); SP.ListItemCollection listItemCollection = myList.GetItems(CamlQuery.CreateAllItemsQuery()); context.Load(listItemCollection, eachItem => eachItem.Include( item => item, item => item["Title"], item => item["ID"] ) ); context.ExecuteQuery(); foreach (SP.ListItem listItem in listItemCollection) { Console.WriteLine("ID: " + listItem["ID"].ToString() + "Title: " + (string)listItem["Title"].ToString()); } Console.ReadKey(); } } } }2.3KViews1like1Comment
Recent Blog Articles
No content to show