Monday, May 30, 2011

How to get SharePoint user profile information from Account Name


using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;

private string GetPreferredName(string accountName)
{
SPSite site = SPContext.Current.Web.Site;
ServerContext context = ServerContext.GetContext(site);
UserProfileManager profileManager = new UserProfileManager(context);
try
{
UserProfile profile = profileManager.GetUserProfile(accountName);
return profile[PropertyConstants.PreferredName].ToString();
}
catch
{
return accountName;
}
}

No comments:

Post a Comment