2015-03-24 88 views
1

好的,我正在使用一個Caml查詢從SharePoint列表中檢索一個項目。我通過字段值得到項目循環到我想要的字段值。我的問題是我需要將那個是一個FieldUserValue數據類型轉換爲一個正常的用戶數據類型。有一種方法從用戶檢索FieldUserValue而不是周圍的其他方式...C#將Microsoft.Sharepoint.Client.FieldUserValue轉換爲Microsoft.Sharepoint.Cliend.User

User Usr; 


     foreach (ListItem item in items) 
     { 
      foreach (var f in item.FieldValues) 
      { 
       if (f.Key == "ColumnTitleofDataTypePersonorGroup") 
       { 
        //Error Message 
        Usr = f.Value; 
       } 
      } 

     } 

的詳細ErrorMessages說 錯誤2無法隱式轉換類型「對象」到「Microsoft.SharePoint.Client.User」。一個顯式轉換存在(是否缺少強制轉換?)
我想我只是失去了一些東西明顯.. 感謝提前任何幫助..

回答

6

下面的例子演示瞭如何獲得User objectFieldUserValue object

var list = ctx.Web.Lists.GetByTitle(listTitle); 
var item = list.GetItemById(itemId); 
ctx.Load(item); 
ctx.ExecuteQuery(); 

var author = (Microsoft.SharePoint.Client.FieldUserValue) item["Author"]; 
var authorUser = ctx.Web.SiteUsers.GetById(author.LookupId); 
ctx.Load(authorUser); 
ctx.ExecuteQuery();