3

次のコードを使用して、Sharepoint2010サイトのユーザーのマイサイトから値「Office」を取得しようとしています。

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は常にNullを返します。メタデータが管理されているからだと思いますが、それが問題かどうかはわかりません。

同じコードのさまざまなバリエーションも試しましたが、喜びはありませんでした。

何か案が?

4

1 に答える 1

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

最初にnullを処理してみてください。

于 2012-07-27T14:44:43.163 に答える