Displaying a User Profile Property
-
09-12-2019 - |
Question
I have a user profile property called "PWResetMSG" The contents of that property display the following:
Password will Expire in x days
Where x is the number of days that remain until the user must reset his or her AD password. All I want to do is expose this property so that I can display it to the end user on a SharePoint Site. The property is updated every morning.
Is there an easy way for me to expose the custom property to the end user?
Solution
You can configure the property to show in their profile if you want to show it there.
Another option would be to load it into a user control added to the masterpage or a web part to display it on selected pages. You can then configure it to display the message you want to show.
Accessing the data is done through the UserProfileManager and UserProfile objects
SPServiceContext svcContext = SPServiceContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(svcContext);
UserProfile profile = profileManager.GetUserProfile(accountname);
string resetDays = profile["PWResetMSG"].Value;