How to: Retrieve User Profile Properties

This code 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.SharePoint

  • System.Web

Example

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("https://servername"))
            {
                   ServerContext context = 
                       ServerContext.GetContext(site);
                   UserProfileManager m_mngr = new UserProfileManager(context);

                   //Get the properties
                   PropertyCollection props = m_mngr.Properties;
                   foreach (Property prop in props)
                   {
                       Console.WriteLine(prop.Name);
                   }

               }
            }

        }
    }

See Also

Tasks

How to: Retrieve a User Profile
How to: Retrieve What's Common Between Two User Profiles
How to: Get Recent User Profile Changes Using the Change Log