Consider a case where you need to pull information from User profile service application depending upon the property you supply in function.

As shown in above image suppose you need to have User Profile Picture,User Display name,Designation,Location,Full profile view address etc. etc. Here function GetUserProfile Property takes the parameters like Account Name and Property to extract.Simply supply those parameters and Enjoy!!!

As shown in above image suppose you need to have User Profile Picture,User Display name,Designation,Location,Full profile view address etc. etc. Here function GetUserProfile Property takes the parameters like Account Name and Property to extract.Simply supply those parameters and Enjoy!!!
- /// <summary>
- /// Method to extract user profile property details
- /// </summary>
- /// <param name="AccountName">Account name of logged in User</param>
- /// <param name="propertyName">Property name to extract</param>
- /// <returns>a sting with property value</returns>
- public string GetUserProfileProperty(string AccountName, string propertyName)
- {
- string resultValue = string.Empty;
- try
- {
- SPSecurity.RunWithElevatedPrivileges(delegate()
- {
- SPServiceContext oSPServiceContext = SPServiceContext.GetContext(SPContext.Current.Site);
- UserProfileManager oUserProfileManager = new UserProfileManager(oSPServiceContext);
- UserProfile oUserProfile = oUserProfileManager.GetUserProfile(AccountName);
- if (oUserProfile != null)
- {
- resultValue = oUserProfile[propertyName].Value.ToString();
- }
- });
- return resultValue;
- }
- catch (Exception ex)
- {
- throw;
- }
- }
Happy SharePoint !!!

Join the conversation! Your thoughts help the community grow.