Archive for June, 2008

SharePoint’s hidden user-list – User Information List

June 25th, 2008 by Tobias Zimmergren

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(@"ZIMMERTobiasZimmergren");

// 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.

Back on track

June 10th, 2008 by Tobias Zimmergren

I’ve been getting tons and tons of mail from people regarding the blog, Forum Webpart and my vacation during the last 3 weeks.

There has been quite a few things happening the last couple of weeks. Not only the awesome vacation I had in Egypt, but also moving into my new apartement.

Egypt

Hats off to Egypt, and to the people who recommended me to go there. It’s an interesting place to visit, and there’s plenty of souvenirs to buy if you’re that kind of person (Like me). Part from just purchasing souvenirs the Red Sea is probably one of the best places in the world to dive and snorkel in. We went snorkling in the Red Sea and holy cow, it’s awesome. Incredible-looking fishes swimming right next to you, almost checking you out as you dive around. It was like swimming straight into the Discovery Channel or a giant aquarium if you like.

New apartement

The other thing that has obsorbed most of my sparetime (blogtime, sharepoint-coder-time etc) is my new apartement which I moved into this weekend. If you’ve got your ways through Malmö (Down south in Sweden), you’re welcome to pay me a visit for some never-ending SharePoint nerd talk and a beer or two.

SharePoint Forum WebPart

People have been bugging me lately about the SharePoint Forum WebPart, and getting a working version out there. As mentioned before, other things did get my focus the last couple of weeks – but now I’m back and I need your suggestions, which I’ll leave the next blogpost for!

Thanks for tuning in, and please re-send any emails I might have accidentally sorted out during the crazy hours of mail-sorting the last couple of days ;)