Thursday, October 23, 2008

Update WSS 3.0 User Profile Programmatically

In WSS 3.0, there is a special list ‘User Information List’ for user’s profile information. When a user is added to the Sharepoint site, a list item is automatically created in this list. To update the user’s information in ‘User Information List’, for instance, to update the user’s photo, I am using following code and it works fine:

 

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

SPUser u = web.SiteUsers[“domain\\user1”];

.SPListItem it = list.Items.GetItemById(u.ID);

 

it[“Picture”] =”http://sharepointApp/sites/wss/photos/abc.jpg”;

it.Update();

 Also, you are able to add a custom field to user profile like this:

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

if (!list.Fields.ContainsField("Favorites"))
{
         list.Fields.Add("Favorites", SPFieldType.Text, false);
         list.Update();
}