Retrieve User Profile information and display all properties in simple webpart

When working with User Profiles I want an overview of all user profile properties and the contents of a particular user. This information can be retrieved from the Central Administration. The downside of this is you can either view the profile properties or the user profile. But I am looking for the display name, technical name and the value for a particular user.

User Profile WebPart

This can be achieved by developing a webpart which loops the user profile properties and retrieves per property the value of an user profile. The user profile which is displayed can be set in the webpart properties pane.

User Profile WebPart - Property Pane

The C# code which drives the webpart is shown below. It is pretty straight forward and shows only the retrieval of the user profile properties and values of the user profile.

System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted); ps.Assert(); Microsoft.SharePoint.SPServiceContext serviceContext = Microsoft.SharePoint.SPServiceContext.Current; UserProfileManager upm = new Microsoft.Office.Server.UserProfiles.UserProfileManager(serviceContext); ProfileSubtypePropertyManager pspm = upm.DefaultProfileSubtypeProperties; UserProfile profile = upm.GetUserProfile("CONTOSO\AaronP"); this.Controls.Add(new Literal() { Text = "<table border='0' > <tr><td>Displayname</td><td>Name</td><td>Value</td></tr>" }); foreach (ProfileSubtypeProperty prop in pspm.PropertiesWithSection) { if (prop.IsSection) this.Controls.Add(new Literal() { Text = string.Format("<tr><td colspan='3'><b>Section: {0}</b></td></tr>", prop.DisplayName) }); else { string text = string.Format("<tr><td>{0}</td><td>{1}</td><td>{2}</td></tr>", prop.DisplayName, prop.Name, profile[prop.Name].Value); this.Controls.Add(new Literal() { Text = text }); } } this.Controls.Add(new Literal() { Text = "</table>" });

DownloadYou can download the WSP package and source code at http://sp2010userprofilewp.codeplex.com/.