MOSS User Profile(四):代码创建用户配置文件
2007-11-06 10:43
483 查看
MOSS User Profile(四):代码创建用户配置文件
用户配置文件的创建在前面介绍过,只要用户登录过自己的“我的网站”就会被创建好了。其实,通过对象模型也是可以提前创建好用户的配置文件的,可以省去用户必须登录我的网站才能创建自己的配置文件的过程。而且在对象模型中创建用户的配置文件其实也是比较简单的。只需要具备权限的用户并提供需要创建配置文件的用户帐户名就OK了。
同前面的方法一样,首先要从上下文获取这个很重要的管理类的对象UserProfileManager。
然后,我们有几个方法可以使用:
这里我们用到的是第一个方法CreateUserProfile和最后一个UserExists。
代码如下:
文中代码来源自参考资料。
参考资料:Sams Microsoft SharePoint 2007 Development Unleashed
用户配置文件的创建在前面介绍过,只要用户登录过自己的“我的网站”就会被创建好了。其实,通过对象模型也是可以提前创建好用户的配置文件的,可以省去用户必须登录我的网站才能创建自己的配置文件的过程。而且在对象模型中创建用户的配置文件其实也是比较简单的。只需要具备权限的用户并提供需要创建配置文件的用户帐户名就OK了。
同前面的方法一样,首先要从上下文获取这个很重要的管理类的对象UserProfileManager。
SPSite site = new SPSite("http://mossweb:1111/sites/Publish"); ServerContext context = ServerContext.GetContext(site); UserProfileManager profileManager = new UserProfileManager(context); |
方法名 | 描述 |
CreateUserProfile | 创建一个用户配置文件 |
GetChanges | 获取用户配置文件的修改历史记录 |
GetUserProfile | 获取一个用户配置文件 |
RemoveUserProfile | 移除一个用户配置文件 |
UserExists | 判断用户是否已经具有配置文件 |
代码如下:
using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using System.Web; using Microsoft.Office.Server; using Microsoft.Office.Server.Administration; using Microsoft.Office.Server.UserProfiles; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { try { using (SPSite site = new SPSite("http://mossweb:1111/sites/Publish")) { ServerContext context = ServerContext.GetContext(site); UserProfileManager profileManager = new UserProfileManager(context); string accountId = @"eoffice"administrator"; if (!profileManager.UserExists(accountId)) { UserProfile profile = profileManager.CreateUserProfile(accountId); if (profile == null) Console.WriteLine("Could not create profile, an error occurred."); else Console.WriteLine("User profile created."); } else Console.WriteLine("User profile for account " + accountId + " already exists."); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadLine(); } } } |
参考资料:Sams Microsoft SharePoint 2007 Development Unleashed
相关文章推荐
- MOSS User Profile(四):代码创建用户配置文件
- MOSS User Profile(四):代码创建用户配置文件
- MOSS User Profile(三):查看用户配置文件修改历史
- MOSS User Profile(二):用户配置文件属性
- MOSS User Profile(二):用户配置文件属性
- MOSS User Profile(五):操作用户配置文件属性
- MOSS User Profile(五):操作用户配置文件属性
- MOSS User Profile(二):用户配置文件属性
- MOSS User Profile(五):操作用户配置文件属性
- MOSS User Profile(三):查看用户配置文件修改历史
- MOSS User Profile(三):查看用户配置文件修改历史
- “User Profile Service 服务未能登录,无法加载用户配置文件”实战历程
- linux创建用户 限制权限-用户(User)和用户组(Group)配置文件详解
- window7 专业版 User Profile Service,无法加载用户配置文件
- User Profile Service Stuck on Starting --用户配置文件停在“启动中”
- win7 启动报错:user profile service服务不能登录无法加载用户配置文件
- User Profile Synchronization Service Gets Stuck on Starting 用户配置文件同步服务卡在“启动中”的解决方案
- linux创建用户 限制权限-用户(User)和用户组(Group)配置文件详解
- 【经验之谈】“User Profile Service 服务未能登录,无法加载用户配置文件”实战历程
- SharePoint 2013 开发——获取用户配置文件属性内容(User Profile)