Thursday, October 3, 2013

Add custom profile property in User Information List

Using SharePoint 2010;

Requirement: To add/read a custom profile property in My Settings page/ User Information List.

To read profile property and values:

            string fieldName = string.Empty;
            using (SPSite site = new SPSite("http://SiteURL"))
                using (SPWeb web = site.OpenWeb())
                    SPList userInfoList = web.SiteUserInfoList;
                    SPUser user = SPContext.Current.Web.EnsureUser(login);
                    SPListItem userItem = userInfoList.Items.GetItemById(user.ID);

                    foreach (SPField field in userInfoList.Fields)
                        fieldName = field.Title;
                        Console.WriteLine(fieldName + "\t " + userItem[fieldName]);

To add a custom profile property:

//Create custom profile property
   SPField newTextfield = userInfoList.Fields.CreateNewField(SPFieldType.Text.ToString(), "Personal Web Site");                  

Few facts about My Settings Page:

1. Keep in mind that “My Profile” and “My Settings” are two completely different things.  My Profile is looking at information directly from the Profile Database.  My Settings is site specific, and is looking at information at the current site.

2. If the User Profile service application is not enabled when you visit the site initially, your data is retrieved from the Active directory and stored in the content database "User Information List"

3. User Information List is a hidden list. You can access it programmatically or using PowerShell.

4. In People and Group page (http://<sitecollection>/_layouts/people.aspx), it appears as a SharePoint list. Fields can be added or removed to suit the business needs.

5. List events are not raised on the User Information list type. There is no resolution as of now as per Microsoft. Refer:

6. My Settings is the local site collection profile. The UserInfo table (DB instance of ‘User Information List’) is a table stored in the Content Database for each Site Collection.

7. If User Profile is not configured and there are no My sites, then we can use User Information List available per each Site Collection where minimal data is available, such as AD account, SID, Email, First name, last name.

8. Custom properties in User Information List can be added from ‘People and Groups’ site collection page by Site Collection Administrators.

No comments:

Post a Comment