Windows Live Alerts web tracker BlogRankers.com Software
Computers blogs
Chat with me if I'm online!
Search Zimmergren.net
Goodies

SharePoint's hidden user-list - User Information List 

Okay, this might not come as news to most SharePoint developers who've been around a while, but lately I've been messing with the User Information List in SharePoint and it doesn't seem that many people know that it exists.

Note: This list is only visible to and accessible by administrators.

User Information List - Background

The User Information List stores information about a user by having some metadata set up for the user. Some examples are Picture, Email, DisplayName, LoginName etc. ) For a complete list of fields, see further down this blogpost under "User Information List Fields".

Something to note is that when a user is granted access to a site, a new item will be created in the User Information List storing some information about the user.

When a user add/create or edit an item, SharePoint will display something like "Last modified at 1/1/2008 by Tobias Zimmergren" like the following pic:

image

In this example the DisplayName (used to display System Account) is gathered from the User Information List

Browsing the User Information List

The User Information List can be accessed (Only if you're admin) via the browser by navigating to /_catalogs/users/simple.aspx from your site. (Ex: http://zimmergren/_catalogs/users/simple.aspx)

This works for both Windows SharePoint Services 3.0 (WSS 3.0) and Microsoft Office SharePoint Server 2007 (MOSS 2007) and looks like this when you access it through the browser:

image

Write code to interact with the User Information List

If you want to interact with this list to set properties on a user (Probably only want to do this if you're running WSS) you could do it like this:

// Instantiates the User Information List
SPList userInformationList = SPContext.Current.Web.SiteUserInfoList;

// Get the current user
SPUser user = SPContext.Current.Web.EnsureUser(@"ZIMMER\TobiasZimmergren");

// The actual User Information is within this SPListItem
SPListItem userItem = userInformationList.Items.GetItemById(user.ID);

The above code will give you the SPListItem object which links to the currently logged in user (the one executing the request).

You can then work with the SPListItem object like normal to get or set the properties like this:

string pictureURL = userItem["Picture"].ToString();

User Information List Fields

Instead of writing out all the fields/columns availible, you can simply create a new Console Application and insert the following code in order to output all the fields names and internalnames:

image
Note: You will ofcourse have to change the URL and User LoginName
Note2: No comments needed about not disposing the objects as this was merely a sample, eh? ;)

You're welcome

Hope this will enlighten some of you people in your quest for the holy grail (SharePoint All-Mighty Knowledge?)

Work is calling me, so I'll have to end this small post right here and right now, catch you soon again.

 
Posted on 25-Jun-08 by Tobias Zimmergren
18 Comments  |  Trackback Url  |  Link to this post | Bookmark this post with:        
Tags: MOSS 2007, WSS 3.0
 

Links to this post (Trackbacks/Pingbacks)

Comments

Wednesday, 25 Jun 2008 09:06 by Andy
yay first comment after published post 3 minutes ago! talk about quick RSS-reader! Good explanation to how you can get stuff from the list by code!

Thursday, 26 Jun 2008 09:10 by Adrian
i red about this list somewhere before but not knowing to access it was possible. this was cool. i did the consoleapplication and added to change the Picture ant it works. however you must use .Update() before the changes are complied if you make changes. cool!

Thursday, 26 Jun 2008 09:20 by Anders Hammer
Let me mention a neat thing about the SPWeb.EnsureUser function; if the user isn't already added to the User Information List, this function will do it. As Tobias wrote, when a user is granted access to a site, it will be added to the list. This function does the same thing (that's why you should always use this function instead of SPWeb.AllUsers, for example).

Thursday, 26 Jun 2008 02:46 by JHatton
We have yet to understand why this User Info comes up when you click on a name instead of being sent to the user's My Site profile. Anyone know how to get them sent to the My SIte (which is more up to date, etc) instead of the User Info screen?

Friday, 27 Jun 2008 07:00 by Russ
JHatton, I believe the reason for the user profile page rather than a direction to the My Site Profile is that there is no guaranteed that My Sites would be enabled for any WSS installation. I recently wrote a feature that plugs into the ProfileRedirection delegate redirecting users to the My Profile page. This is the best solution I have found so far.

Friday, 27 Jun 2008 04:27 by Developer
Coolio man. Cool list i didnt know off. Code works nice

Friday, 27 Jun 2008 08:25 by TJ
Hey Tobias. Could this explain some strange behavior? (See following) User "Joe Bloggs" changes some data so it is displayed "modified by Joe Bloggs". In AD this user then has their last name changed (gets married). Profile imports in central admin reflect this change for the user BUT when the user logs in or makes further changes it still displays "Joe Bloggs"? Has any one witnessed this?

Friday, 27 Jun 2008 11:05 by Tobias Zimmergren
Hi TJ, I havn't encountered the issue myself, however if you read the following blog I bet there's some info which you'll find usefull on the sync-issues: http://blogs.msdn.com/gregmcb/archive/2008/03/15/user-profiles.aspx Cheers!

Tuesday, 1 Jul 2008 12:55 by dude
dude i knew it was soemthing special with this list. been wondering for a long time, but never been able to access it haha. thanks

Thursday, 10 Jul 2008 08:44 by Vivek
Hi Tobias, actually i used this list with the help of CAML query. but now my requirement is littlebit different. Actually i want to get an event when Sharepoint Adds New user to this list..I mean at the first time when User Logs in I want him to redirect to some other page and ask him to do something else...currently I am putting my code in Master page and getting info. But is there any way to Track this kind of EVENT...waiting for your pro answer...

Friday, 11 Jul 2008 12:52 by TJ
I have looked at the list and this is to blame for the wrong name. Although the account has been updated "****\surnamef" the Name hasn't been updated "oldSurname, firstname" What I ask is, is this normal? I.E should this happen like this (bug or not) when an account is changed? Is the only answer to write a custom script to sync often? Vivek. Lists can have events attached. So why not look into list events?

Monday, 21 Jul 2008 01:08 by Ramakrishna
Hi, How to impliment this? We are using WSS 3.0 We have to create usergrps and users from active directory in sharepoint. But my requirements are we have to store 2 to 3 columns of info for every user we are creating in sharepoint. Like User, column1, column2. When we are granting permissions for any resources(like subsites,lists..) than we can able to select from already created grps not from active directory. Actually in some scenarios we need both options(from AD and sharepoint grps). So I though of using Lists to store user and grps, Than how can we refer these lists when we are granting permissions to resources ? Thanks in advance

Wednesday, 6 Aug 2008 03:32 by Priyanka
Hi Tobias, can you tell me some way to link my contacts list with the User Information List. I have a lookup column that takes values from User Information List. Now the problem is when I add a new user in the contacts list, and select some existing one from the lookup, details of the user do not get filled in the other given empty fields. I need to fire some event and fetch values for the selected user from list. But am quite unsure how to achieve this on contacts list. Any ideas? Alternatively, any idea of importing all the users in the information list to Contacts List??

Name:
URL:
Email:
Comments: