Tuesday 17 April 2012

Get User Profile Details Programmatically - SharePoint

In WSS, there is a basic list called the ‘User Information List’ which holds some profile details about the users themselves. These details can be viewed/edited from the ‘My Settings’ screen.

ms

WSS holds the following user details:

  • Account (Login Name)

  • Name (Display Name)

  • E-Mail

  • About Me

  • Picture

  • Department

  • Job Title

  • SIP Address


You can get a reference to any of these properties in code simply by querying the list with the ID of the required SPUser:

e.g.

using (SPSite Site = new SPSite(“Site URL”))

{
using (SPWeb Web = Site.OpenWeb())
{


SPList UserInfoList = Web.Lists[“User Information List”];


SPUser User = Web.Users.GetByID(1); – Put the User ID Here


SPListItem UserItem = UserInfoList.GetItemById(User.ID);


UserItem[“Department”] = “Department Name”;


}


}

Using this list you can set any of the values as required or simply retrieve the stored values. I used the above to get a reference to the ‘Picture’ which is stored as a URL.

No comments:

Post a Comment