2012-07-27 103 views
3

我嘗試使用下面的代碼來獲得在SharePoint 2010網站的價值「辦公室」關閉用戶的MYSITE:獲取Office值off mysites在SharePoint 2010

SPSite site = SPContext.Current.Site; 

     SPServiceContext serviceContext = SPServiceContext.GetContext(oSite); 

     UserProfileManager manager = new UserProfileManager(serviceContext); 

      UserProfile profile = manager.GetUserProfile(oUser.ToString()); 
             var Office = profile[PropertyConstants.Office].Value; 
             var faxnum= profile[PropertyConstants.fax].Value; 

而數字和其他許多值工作正常,Office總是返回空值。我相信這是因爲是託管元數據,但我不確定是什麼問題。

我也嘗試了相同的代碼,但沒有喜悅的不同變化。

任何想法?

回答

2
var Office = profile[PropertyConstants.Office] != null ? profile[PropertyConstants.Office].Value : String.Empty; 

試着先處理null。

+1

Yeap我發現屬性Office不能被用戶更改,但它可能會更新,也許從AD? – user1211929 2012-07-30 08:11:20