Accessing User Profile Information in WSS 3.0

MOSS and WSS 3.0 handle user profiles differently. In MOSS, user profile information is stored centrally and can be shared across site collections. Profiles can be manipulated using the UserProfileManager class found in Microsoft.Office.Server.dll.

Life just isn't the same when working with WSS 3.0. When developing a workflow, for example, it may be useful to access a property of the user profile. You can't use UserProfileManager as it doesn't exist and SPUser doesn't expose most of the profile information. In WSS 3.0 the user profile information is stored in a hidden list specific to an individual site collection. If you have multiple site collections, a different hidden list is used for each site collection. The User Profile Information is just another list and can be treated as such -

SPList userProfileList = web.Lists["User Information List"];

foreach (SPListItem user in userProfileList.Items)
{
    Console.WriteLine(user["Name"] + " " + user["Department"];
}

The cut down C# above lists all the user names and departments.

Accessing the user profile information in WSS 3.0 is straightforward, once you know how ;-)

Filed under:

Comments

# Wael said:

There is a problem here , only administrators can view this list programmatically and how to view it if the looged user is not administrator ?????

please replay here and on my mail wael.mohamed@live.com

thanks

16 July 2008 10:50
# John said:

Found this post you made just recently. It was helpful in at least getting me in the right ball park but the items returned above still seem to be limited. I can not find the Business phone number of a profile for the life of me. Any suggestions?

24 November 2008 18:07
# Iain said:

Sorry Wael, had missed your comment, :-(

Run the code with elevated privileges, e.g.

SPSecurity.RunWithElevatedPrivileges(delegate()

{

   // implementation details omitted

});

Have a look at the MSDN article -

msdn.microsoft.com/.../microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx

06 December 2008 15:01
# Iain said:

Thanks for the comment John. I assume you have added Business Phone to the user profile list from the existing site columns? If so getting the business phone is straightforward. In the above example, simply use user["Business Phone"].

Let me know if this is what you were asking?

06 December 2008 15:20
# Steve said:

Is there any difference between the "User Information List" and the "UserInfo" list?   It appears that the SPUserCollection at SPContext.Current.Web.Users appears to point to "UserInfo" which has a different GUID.  Is this just a subset of data, ie the "Person" ContentType of the "User Information List", and if so can you access custom fields or the row/item data from this object?

I'm trying to create a MembershipContentType that I can add to the "User Information List" along with a SharePointListMembershipProvider and was wondering the easiest way to obtain the requested user, either as a SPUser or a List Item.

29 December 2008 22:32

Leave a Comment

(required) 
(required) 
(optional)
(required)