Wednesday, April 13, 2011

How to get UserProfile information programmatically using SharePoint 2010 object model?





In this post we will discuss how to get UserProfile information programmatically using SharePoint 2010 object model?

Also you can check out:

- Retrieve all site collections inside web application in SharePoint

- How to create a Site Definition using Visual studio 2010 in SharePoint 2010?

- Fix width of master page in SharePoint 2010

To retrieve User Profile information in SharePoint 2010 you should have User Profile Service application configured and activated. Microsoft.Office.Server.UserProfiles.UserProfileManager dll need to reference needed.

SharePoint 2010 object model code to retrieve the data:

using (SPSite site = new SPSite("Site URL"))
{

SPServiceContext context = SPServiceContext.GetContext(site);

UserProfileManager upm = new UserProfileManager(context);

UserProfile profile = upm.GetUserProfile("Domail\\UserName");

String WorkEmail=profile[PropertyConstants.WorkEmail].Value.ToString();

String FirstName = profile[PropertyConstants.FirstName].Value.ToString();

String LastName = profile[PropertyConstants.LastName].Value.ToString();

}



No comments:

Post a Comment