Thursday, February 14, 2013

Access User information from User Profile using SharePoint Object Model

Access User Profile from Console Application to retrieve user information

Most of the time we require user information for our application. the best way to get these information from User Profile. Here is the code which describes how we can connect to User Profile service and get the user information.

I assumed that User Profile service application is already setup by Farm Admin.


I also assumed that you have Web App already created e.g. http://win-urbt9f048vo:9999.

Following is the Code which will access user profile service application to get the information of specific user.

Required Namespace:
  • System.Web
  • Microsoft.Office.Server
  • Microsoft.Office.Server.UserProfile
  • Microsoft.SharePoint

Code 1st Part: Here we are trying to access the Site and pass the User ID to FillUserProfileDetails Function.


Code 2nd Part: Here we are trying to get the service context of the Site. After getting service context creating UserProfileManager Object which will fetch the user data using GetUserProfile method.

GetUserProfile Method require the login id of the user.

Once it return the object UserProfile filled with all information, each property can be individually.
All default properties details can be found here. properties are mapped with AD. yo can also retrieve any custom property created in User Profile.





No comments: