4
我正在尝试为正在处理的SharePoint 2010项目创建“Who is”Web部件。使用UserProfileManager获取随机用户
此Web部件应该从SharePoint配置文件中选择一个随机用户并显示他/她的姓名,部门和电话。
问题是,我找不到一种方法来从用户配置文件直接获取一个随机用户,这正是我想要做的。
我找到了一种方法来做到这一点:
SPServiceContext myContext = SPServiceContext.GetContext(mySite);
SPWeb myWeb = SPContext.Current.Web;
UserProfileManager profileManager = new UserProfileManager(myContext);
bool boolOut;
SPPrincipalInfo[] userInfos = SPUtility.GetPrincipalsInGroup(myWeb, "AllUsers", profileManager.Count, out boolOut);
Random random = new Random();
int randomUser = random.Next(0, userInfos.Length);
SPPrincipalInfo user = userInfos[randomUser];
bool userFound = false;
while(!userFound)
{
if (profileManager.UserExists(user.LoginName))
{
UserProfile userProfile = profileManager.GetUserProfile(user.LoginName);
userDepartment = Convert.ToString(userProfile[PropertyConstants.Department].Value);
userPicture = Convert.ToString(UserProfile[PropertyConstants.PictureUrl].Value);
userFound = true;
}
}
这样我做这可能是一个问题,因为该网站将具有2K +的用户,这就是为什么我想知道是否有可能做到这一点直接从用户配置文件。
我是新来的SharePoint,它仍然有点令我困惑。
感谢您的帮助。
Doug,随机部分仅仅是当你进入页面时显示一个随机的员工,这只是一个被要求我做的细节:/ – 2010-09-02 16:52:38