SharePoint:将新项目添加到具有查找字段的列表时出错

SharePoint:将新项目添加到具有查找字段的列表时出错,sharepoint,sharepoint-2013,Sharepoint,Sharepoint 2013,我有一个SharePoint门户,上面有帖子列表。这些评论可以添加到帖子中。因此,它可以通过SharePoint web界面正常工作。但我的任务是以编程方式添加注释。 若要添加评论,我必须在评论列表中创建新项目,并在其中填写PostID查找字段。但当我尝试这样做时,出现了错误。标题和正文字段已正确保存。 错误消息:已使用无效数据更新列表项。您试图更新的字段可能是只读的。 这是我的代码: clientContext.Credentials = GetCred

我有一个SharePoint门户,上面有帖子列表。这些评论可以添加到帖子中。因此,它可以通过SharePoint web界面正常工作。但我的任务是以编程方式添加注释。 若要添加评论,我必须在评论列表中创建新项目,并在其中填写PostID查找字段。但当我尝试这样做时,出现了错误。标题和正文字段已正确保存。 错误消息:已使用无效数据更新列表项。您试图更新的字段可能是只读的。 这是我的代码:

                    clientContext.Credentials = GetCredentials();
                    SP.List oList = clientContext.Web.Lists.GetById(new Guid("{43fcafd5-52c0-4ed6- 
                                                                     b30d-72a74c796374}"));
                    Field field = oList.Fields.GetByInternalNameOrTitle("PostID");
                    clientContext.Load(field);

                    ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                    ListItem newItem = oList.AddItem(itemCreateInfo);
                    newItem["Body"] = text;
                    else newItem["Title"] = text;
                    FieldLookupValue post = new FieldLookupValue() { LookupId = postId };
                    newItem["PostID"] = post;
                    newItem.Update();
                    clientContext.ExecuteQuery();
我已检查field.ReadOnlyField属性,它设置为false