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
Leave a comment

15 Comments

  1. Great looking webpart. Have you considered creating one that a person could use to edit the profile information or do you know of one?

    Reply
    • Bram de Jager

       /  April 21, 2011

      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.

      Reply
      • 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.

      • Bram de Jager

         /  April 25, 2011

        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!

  2. Thanks, Bram!

    Reply
  3. Sukanya

     /  August 23, 2012

    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??

    Reply
    • Bram de Jager

       /  September 7, 2012

      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;
      }

      Reply
  4. “Retrieve User Profile information and display all properties in simple webpart
    Bram de Jager’s SharePoint blog” was indeed a really nice post, . Continue writing and I’ll keep on
    reading through! Many thanks -Jeramy

    Reply
  5. Smera

     /  March 29, 2013

    Great Post!
    Is there a way to do the same with powershell scripting?

    Reply
    • Bram de Jager

       /  April 3, 2013

      Sure u can, you can use the Microsoft.Office.Server.UserProfiles namespace.

      Reply
  6. Ray G

     /  May 9, 2013

    Great post, thank you. However, any idea why a custom properties are not showing?

    Reply
    • Bram de Jager

       /  May 14, 2013

      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?

      Reply
  7. Hannah Swain

     /  May 14, 2013

    Useful stuff – thanks, Bram!

    Reply
  8. Mike Fox

     /  April 22, 2015

    Awesome information. WOuld it be possible to modify this to display only a specific field?

    Reply

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: