2016-11-21 121 views
0

我正在使用CSOM從sharePoint聯機檢索數據。 我需要從文檔庫中獲取數據。這裏是我用來檢索數據的語法。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

嘗試這樣,FieldUserValue在與用戶合作時非常有用,但在這種情況下,您需要FieldLookupValue

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

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

感謝您的支持。 – RiksonTool