CSOM - Trying to access “Client_Title” from a page in a list - “The property/Field has not been initialized … ”

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/251750

Question

I'm trying to access the "Client_Title/Page Title" from a page in Site Pages using Client Context and "listItemId". It seems that I'm not requesting or loading it the correct way.

When debugging I see that ListItemId is the valid Id of the item.

I appreciate every help I can get.

Problem pic

Était-ce utile?

La solution

I've reworked your code to resolve the issue

  • store the GetById in a variable before sending out the query
  • make sure you include client title in the query of the item
  • it seems you are composing many queries that you end up not using since you know the id of the item you want

e.g.

var changedItem2 = listitem.GetById(listitemId);            
context.Load(changedItem2, item => item.Client_Title);
context.ExecuteQuery();

var title2 = changedItem2.Client_Title;

EDIT:

an even better approach would be to do a single query line and get rid of everything else

var changedItem2 = context.Web.Lists.GetByTitle("Site Pages").GetItemById(listitemId);
context.Load(changedItem2, item => item.Client_Title);
context.ExecuteQuery();
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top