다음을 통해 공유


How to: Retrieve User Profile Properties

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

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"))
            {
                  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);
                    }


               }
            }

        }
    }

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