Export (0) Print
Expand All

How to: Retrieve User Profile Properties

Last modified: March 24, 2010

Applies to: SharePoint Server 2010

This example uses the User Profiles object model to display the user profile properties that exist on the server. Replace servername with an actual value before running the code example. Also add references to the following in your Microsoft Visual Studio project:

  • Microsoft.Office.Server

  • Microsoft.Office.Server.UserProfiles

  • Microsoft.SharePoint

  • System.Web

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using System.Web;

namespace UserProfilesApp
{
    class Program
    {
        static void Main(string[] args)
        {

            using (SPSite site = new SPSite("http://servername"))
            {
                  SPServiceContext context = 
                       SPServiceContext.GetContext(site);
                  ProfileSubtypeManager psm = ProfileSubtypeManager.Get(context);
                  ProfileSubtype ps = psm.GetProfileSubtype(ProfileSubtypeManager.GetDefaultProfileName(ProfileType.User));
                //Get the properties
                  ProfileSubtypePropertyManager pspm = ps.Properties;
                    foreach (ProfileSubtypeProperty profileSubtypeProperty in pspm.PropertiesWithSection )
                    {
                           Console.WriteLine(profileSubtypeProperty.Name);
                    }


               }
            }

        }
    }

Community Additions

ADD
Show:
© 2014 Microsoft