用户配置文件对象模型概述

Microsoft Office SharePoint Server 2007 提供了丰富的对象模型,用于以编程方式处理用户配置文件。本主题为 Microsoft Office SharePoint Portal Server 2003 用户概述了对象模型的主要变化。有关操作方法的信息,请参阅以下章节:

使用对象模型配置用户配置文件存储区

使用对象模型访问用户配置文件存储区

使用用户配置文件对象模型

在 SharePoint Portal Server 2003 中,您使用 Microsoft.SharePoint.Portal.UserProfiles 命名空间来处理用户配置文件和“我的网站”。但在 Office SharePoint Server 2007 中,应使用 Microsoft.Office.Server.dll 中的 Microsoft.Office.Server.UserProfiles 命名空间。该新的命名空间为 Office SharePoint Server 2007 中的用户配置文件提供对象模型支持。Microsoft.SharePoint.Portal.UserProfiles 命名空间仍然存在,以便向后兼容。您使用 Microsoft.SharePoint.Portal.UserProfiles 命名空间在 SharePoint Portal Server 2003 中编写的应用程序和工具仍可以在 Office SharePoint Server 2007 中使用。但请注意,其表现可能与所预期的不同,尤其是在使用新的用户配置文件功能时更是如此(有关这些功能的详细信息,请参阅用户配置文件和访问群体设定中的新增功能)。

例如,如果您使用 Microsoft.SharePoint.Portal.UserProfiles API 来获取 Office SharePoint Server 2007 中用户配置文件属性的集合,他们只会返回与 SharePoint Portal Server 2003 兼容的单值属性。将忽略新的多值属性和具有选项列表的任何属性。因此,如果您要编写新的应用程序或升级旧的应用程序,则应采用 Microsoft.Office.Server.dll 中新的 Microsoft.Office.Server.UserProfiles 命名空间。Microsoft.SharePoint.Portal.UserProfiles 命名空间中的所有类均已弃用,您每次使用该命名空间中的类或方法时都将收到一条警告消息。

重要

Office SharePoint Server 2007 SDK 中的 API 参考信息仍在不断完善中。若要了解 API 参考信息,请参阅 Microsoft Office SharePoint Portal Server 2003 SDK。

在 Office SharePoint Server 2007 中获取 UserProfileManager 对象

虽然您在 SharePoint Portal Server 2003 中使用的用于获取 UserProfileManager 对象的语法仍然有效(由于向后兼容的缘故),但这里要向您介绍使用 Office SharePoint Server 2007 中的用户配置文件对象模型编写代码的新方法。

运行代码之前,请将 servername 替换为 Office SharePoint Server 2007 服务器名称。

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)
        {
            try
            {
                using (SPSite site = new SPSite("https://servername"))
                {
                    ServerContext context = 
                        ServerContext.GetContext(site);
                    UserProfileManager profileManager = new 
                        UserProfileManager(context);
                    foreach (UserProfile profile in profileManager)
                    {
             Console.WriteLine(profile[PropertyConstants.AccountName]);
                    }
                }
            }
            catch (FileNotFoundException exception)
            {
                Console.WriteLine(exception.ToString());
            }
        }
    }
}

See Also

其他资源

使用对象模型配置用户配置文件存储区

使用对象模型访问用户配置文件存储区