在 sharepoint 中按组获取用户 [英] get users by group in sharepoint

查看:44
本文介绍了在 sharepoint 中按组获取用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何使用 sharepoint 获取特定组中的用户?

can anyone show me how to get the users within a certain group using sharepoint?

所以我有一个包含用户和/或组的列表.我想检索该列表中的所有用户.有没有办法区分列表项是组还是用户.如果是一个组,我需要获取该组内的所有用户.

so i have a list that contains users and or groups. i want to retrieve all users in that list. is there a way to differentiate between whether the list item is a group or user. if its a group, i need to get all the users within that group.

我使用的是 c#,并且我试图通过将它变成一个控制台应用程序来进行精简.

im using c#, and im trying to do thins by making it a console application.

我是 sharepoint 的新手,我真的很喜欢这里的池子深处,任何帮助将不胜感激.

im new to sharepoint and im really jumping into the deep end of the pool here, any help would be highly appreciated.

干杯..

推荐答案

您需要知道的第一件事是,当您有一个包含用户/组字段的列表时,您必须了解它的类型.当项目值中有一个用户或组时,字段类型为 SPFieldUserValue.但是,如果字段有多个用户/组选择,则字段类型为 SPFieldUserValueCollection.
我假设您的字段允许单个用户/组选择,并且您已经拥有以下对象:

The first thing you need to know is that when you have a list with a User / Group field you must be aware of its type. When you have one user or group within the item value, the field type is SPFieldUserValue. However, if the field has multiple user / group selection the field type is SPFieldUserValueCollection.
I'll assume that your field allows a single user / group selection and you already has the following objects:

SPSite site;
SPWeb web;
SPListItem item;

现在,我们将检查用户/组的字段值并检索用户列表,无论它是哪种类型(字段的名称是用户").

Now, we'll check the field value for a user / group and retrieve a list of users, independant of which kind it is (the field's name is "Users").

SPFieldUserValue usersField = new SPFieldUserValue(mainWeb, item["Users"].ToString());
bool isUser = SPUtility.IsLoginValid(site, usersField.User.LoginName);
List<SPUser> users = new List<SPUser>();

if (isUser)
{
    // add a single user to the list
    users.Add(usersField.User);
}
else
{
    SPGroup group = web.Groups.GetByID(usersField.LookupId);

    foreach (SPUser user in group.Users)
    {
        // add all the group users to the list
        users.Add(user.User);
    }
}

希望能帮到你.

Tks,
佩德罗·何塞·巴蒂斯塔

Tks,
Pedro José Batista

这篇关于在 sharepoint 中按组获取用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆