From a SharePoint Add-in, provider hosted, using C# and the client object model, I am trying to get the value of a sharepoint content field on a publishing page.
I tried first:
List list = clientContext.Web.Lists.GetByTitle("Pages");
ListItem item = list.GetItemById(7020);
clientContext.Load(list);
clientContext.Load(item, p => p.FieldValues["QP_Question"]);
clientContext.ExecuteQuery();
ViewBag.Question = item.FieldValues["QP_Question"];
I received this error:
Microsoft.SharePoint.Client.InvalidQueryExpressionException
The query expression 'p.ListItem.FieldValues.get_Item("QP_Question")' is not supported.
Then I tried:
List list = clientContext.Web.Lists.GetByTitle("Pages");
ListItem item = list.GetItemById(7020);
PublishingPage pp = PublishingPage.GetPublishingPage(clientContext, item);
clientContext.Load(list);
clientContext.Load(item);
clientContext.Load(pp, p => p.ListItem.FieldValues["QP_Question"]);
clientContext.ExecuteQuery();
ViewBag.Question = pp.ListItem.FieldValues["QP_Question"];
Still the same error.