You have a custom user profile property named MyProperty.
You need to create a Web Part that displays the value of MyProperty for the current user.
Which code segment should you use?
A.
string profile = SPContext.Current.Web.Properties(“CurrentUser/MyProperty”);
B.
string profile = SPContext.Current.Web.Users[“MyProperty”].ToString();
C.
UserProfileManager profileManager = new UserProfileManager(SPServiceContext.Current);
UserProfile userProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
string profile = userProfile[“MyProperty”].ToString();
D.
UserProfileManager profileManager = new UserProfileManager(SPServiceContext.Current);
UserProfile userProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
string profile = userProfile.Properties.GetPropertyByName(“MyProperty”).ToString();
Explanation:
MNEMONIC RULE: GetPropertyByNameuserProfile.Properties is ProfileSubtypePropertyManager object. See its members in this MSDN article:
ProfileSubtypePropertyManager Members
http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.profilesubtypepropertymanager_members.aspxSee the sample code at the link below.
Creating profile properties and sections the SharePoint 2010 way part 2, The code
http://pholpar.wordpress.com/2010/03/17/creating-profile-properties-and-sections-the-sharepoint-2010-way-part-2-the-code/