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/.

Advertisements

15 thoughts on “Retrieve User Profile information and display all properties in simple webpart

Add yours

    1. Hi Stewart, I created this web part for testing purpose. Mainly getting an overview of the display name, internal name and the actual value. Changing the value’s can be done by the user in the Edit Details page or you can change it in the User Profile Service application when needed.

      1. Thanks for the response. However, have you come across anything that will edit user profiles with SP Foundation 2010? Since the User Profile Service is not available, we are unable to edit that info using that method and the only thing available to edit in the Edit Details page is the Mobile Number. Thanks for any hints you may have.

      2. Stewart, the User Profile Service is part of the SharePoint Server 2010 Standard or Enterprise. This is why you are not able to use the methods described in this blog post.
        You can only edit user information in the Users list (People and Groups) in a site collection. Good luck!

  1. Great looking webpart..i tried your code its working Bram Thank u so much. But my requirement is to get all users profile information and to export into SQL SERVER table…can u pls guide me??

    1. Hi Sukanya, you can use the upm.GetEnumerator() together with a While-loop. Something like this should get you started. Good luck.

      var enum = upm.GetEnumerator();
      while (enum.MoveNext()) {
      UserProfile profile = enum.Current;
      }

    1. Not sure why it would not show the custom properties. Did not explicitly check this but would expect to show these as well. Maybe it has to do with your UPA connected to the web application or authorization?

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

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: