SharePoint查找字段返回空值

时间:2016-11-21 18:43:09

标签: c# sharepoint csom

我正在使用CSOM从sharePoint在线检索数据。 我需要从文档库中获取数据。这是我用来检索数据的语法。

List list = clientContext.Web.Lists.GetByTitle("Required Documents");
if (list != null)
{
CamlQuery caml = new CamlQuery();
caml.ViewXml = @"<View>
                  <Query>
                    <Where>
                       <Eq>
                         <FieldRef Name='PONo' />
                         <Value Type='Lookup'>" + poNo + @"</Value>
                        </Eq>
                    </Where>
                 </Query>                                            
                </View>";                                               

ListItemCollection items = list.GetItems(caml);
clientContext.Load<ListItemCollection>(items);
clientContext.ExecuteQuery();

这里PONo是另一个列表项的查找。 所以我试着得到如下的值,但它返回null。

var itm = item.FieldValues["PONo"] as FieldUserValue;

尝试这样的时候,

var itm = item.FieldValues["PONo"];

它返回需要的价值。会有什么问题?

1 个答案:

答案 0 :(得分:1)

尝试这样,FieldUserValue在与用户合作时非常有用,但在这种情况下,您需要FieldLookupValue

var PONo = item["PONo"] as FieldLookupValue;

if (PONo!= null)
{
    var PONo_Value = PONo.LookupValue;
    var PONo_Id = PONo.LookupId;
}