Search This Blog

Wednesday, October 14, 2015

How to acces sharepoint 2013 user profile using C#

UserProfile profile;
SPServiceContext serviceContext = SPServiceContext.GetContext(SPContext.Current.Site);
string fromMail = string.Empty;

public void getEmailID()
{
    try
    {
        UserProfileManager upm = new UserProfileManager(serviceContext);
        profile = upm.GetUserProfile(currentUser.LoginName);
        if (profile != null)
         {
             if (!string.IsNullOrEmpty(Convert.ToString(profile[PropertyConstants.WorkEmail].Value)))
              {
                    fromMail = profile[PropertyConstants.WorkEmail].Value.ToString();            
              }
         }
    }
    catch (Exception ex)
    {
       throw;    
    }
 }

Using this UserProfileManger we can access all the details stored for a sharepoint user in User Profile Service Application.

thanks,

No comments:

Post a Comment

Restricting Custom People Picker to only one Sharepoint group programatically

Refer the following script files in your page,     <!-- For People Picker -->     <script type="text/javascript" src...