代码之家  ›  专栏  ›  技术社区  ›  RiksonTool

SharePoint查找字段返回空值

  •  0
  • RiksonTool  · 技术社区  · 8 年前

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

    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();
    

    所以我尝试得到如下值,但它返回null。

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

    当这样尝试时,

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   Jaime Macias    8 年前

    像这样试试, FieldUserValue 在处理用户时非常有用,但在这种情况下,您需要 FieldLookupValue .

    var PONo = item["PONo"] as FieldLookupValue;
    
    if (PONo!= null)
    {
        var PONo_Value = PONo.LookupValue;
        var PONo_Id = PONo.LookupId;
    }