从一个SharePoint插件,提供商托管,使用c#和客户端对象模型,我试图得到一个SharePoint内容字段在发布页面的值。
I try 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"];
我收到这个错误:
Microsoft.SharePoint.Client.InvalidQueryExpressionException
The query expression 'p.ListItem.FieldValues.get_Item("QP_Question")' is not supported.
Then I try:
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"];
还是同样的错误
正确的代码是
List list = clientContext.Web.Lists.GetByTitle("Pages");
ListItem item = list.GetItemById(7020);
clientContext.Load(list);
clientContext.Load(item, p => p["QP_Question"]);
clientContext.ExecuteQuery();
ViewBag.Question = Convert.ToString(item["QP_Question"]);
是p.["QP_Question"]
而不是p.FieldValues["QP_Question"]
要查询多个内容字段,请这样做:
clientContext.Load(item, p => p["QP_Question"], p => p["QP_Answer"]);