User Profiles Object Model Overview

SharePoint 2007

Microsoft Office SharePoint Server 2007 offers a rich object model for programmatically manipulating user profiles. This topic summarizes the major changes in the object model for Microsoft Office SharePoint Portal Server 2003 users. For how-to information, see the following sections:

Configuring the User Profile Store Using the Object Model

Accessing the User Profile Store Using the Object Model

Using the User Profiles Object Model

In SharePoint Portal Server 2003, you use the Microsoft.SharePoint.Portal.UserProfiles namespace to work with a user’s profile and My Site. However, in Office SharePoint Server 2007, you should use the Microsoft.Office.Server.UserProfiles namespace in Microsoft.Office.Server.dll. This new namespace provides object model support for user profiles in Office SharePoint Server 2007. The Microsoft.SharePoint.Portal.UserProfiles namespace still exists for backward compatibility. Your applications and tools written in SharePoint Portal Server 2003 using the Microsoft.SharePoint.Portal.UserProfiles namespace should still work in Office SharePoint Server 2007. However, note that they may not behave as expected, specifically when using the new user profiles features (for more information on these features, see What's New in User Profiles and Audience Targeting).

For example, if you use the Microsoft.SharePoint.Portal.UserProfiles APIs to get the collection of user profile properties in Office SharePoint Server 2007, they will return only single-valued properties compatible with SharePoint Portal Server 2003. They will ignore the new multivalued properties and any properties that have choice lists. Therefore, if you are writing new applications or upgrading old applications, you should use the new Microsoft.Office.Server.UserProfiles namespace in Microsoft.Office.Server.dll. All classes in the Microsoft.SharePoint.Portal.UserProfiles namespace have been deprecated, and you will get a warning every time you use a class or method in that namespace.


API reference information in the Office SharePoint Server 2007 SDK is a work in progress. For API reference information, see the Microsoft Office SharePoint Portal Server 2003 SDK.

Getting the UserProfileManager Object in Office SharePoint Server 2007

Although the syntax you used to get the UserProfileManager object in SharePoint Portal Server 2003 still works (because of backwards compatibilty), here is the new way to write code by using the User Profiles object model in Office SharePoint Server 2007.

Before running the code, replace servername with your Office SharePoint Server 2007 server name.

using Microsoft.Office.Server;
using Microsoft.Office.Server.Administration;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;

namespace AccountNameDump
    public class Program
        public static void Main(string[] args)
                using (SPSite site = new SPSite("http://servername"))
                    ServerContext context = 
                    UserProfileManager profileManager = new 
                    foreach (UserProfile profile in profileManager)
            catch (FileNotFoundException exception)

See Also

Community Additions