Home > SharePoint, wss > Adding custom user profile properties in WSS 3.0

Adding custom user profile properties in WSS 3.0


WSS 3.0 uses a hidden list known as the “User Information List” to store the user Information. When a user is added to a site, a new item is created in the User Information List storing information (metadata) about the user.
The User Information List can be accessed via the browser by navigating to “/_catalogs/users/simple.aspx” from your site e.g. (http://%7byoursite%7d/_catalogs/users/simple.aspx)
Note: This list is only visible/accessible to site administrators
Hence, with the above background creating a new User Profile property is as simple as adding a field to this list :-). Following code snippet adds two fields to the user profile i.e. OrgId and OrgName
Code Snippet:

SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite("{YourSiteUrl}"))
{
using (SPWeb web = site.OpenWeb())
{
SPList usersList = web.Lists["User Information List"];
if (!usersList.Fields.ContainsField("OrgId"))
{
usersList.Fields.Add("OrgId", SPFieldType.Number, false);
}
if (!usersList.Fields.ContainsField("OrgName"))
{
usersList.Fields.Add("OrgName", SPFieldType.Text, false);
}
usersList.Update();
}
}
});

Here is the snapshot of user profile page after adding two new fields

Untitled

Advertisements
Categories: SharePoint, wss
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: