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!!!
-
-
-
-
-
-
- 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;
- }
- }