如何列出 SPGroup 中的所有 SPUser 对象?
我需要从 SPGroup
检索所有 SPUser
。不幸的是,该组可能包含 Active Directory 组,因此简单的 SPGroup.Users
是不够的(我只需为 AD 组获取一个 SPUser
,其中 < code>IsDomainGroup 属性设置为 true)。
有谁知道如何获取所有 SPUser
的列表,并深入到 SPGroup
中包含的任何 Active Directory 组?是否有替代采用 SPUser
参数的 SPGroup.ContainsCurrentUser
的方法?
I need to retrieve all SPUser
's from a SPGroup
. Unfortunately, the group may contain Active Directory groups, so a simple SPGroup.Users
is not enough (I'd just get a single SPUser
for the AD group, with the IsDomainGroup
property set to true).
Does anyone have a good idea how can I obtain a list of all SPUser
's, descending into any Active Directory groups contained in a SPGroup
? Is there an alternative to SPGroup.ContainsCurrentUser
that takes a SPUser
parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
基于我发现的博客文章,我编写了以下代码:
我不喜欢必须模拟每个用户的事实,并且此代码只会查找已导入 SharePoint 的 AD 用户(因此
SPUser
对他们来说存在),但这对我来说已经足够了。Based on a blog post I found, I have written the following code:
I don't like the fact that I have to impersonate every single user, and this code will only find AD users that have already been imported into SharePoint (so an
SPUser
exists for them), but that's good enough for me.不幸的是,可能并非 AD 组的每个成员在站点中都有相应的 SPUser 对象。
在这种情况下,我将枚举 Active Directory 组的所有成员,并使用 SPWeb 的
EnsureUser()
方法强制他们进入站点,该方法返回SPUser
,如果站点中尚不存在,则创建一个新的。有关枚举 Active Directory 成员的指南,请参阅 从给定 AD 组中的 Active Directory 获取用户列表。
Unfortunately, it may be the case that not every member of the AD group has a corresponding SPUser object in the site (yet).
In this scenario, I'd enumerate all the members of the active directory group, and force them into the site with the SPWeb's
EnsureUser()
method, which returns anSPUser
, and creates a new one if it doesn't already exist in the site.For guidance on enumerating active directory members, see Get List of Users From Active Directory In A Given AD Group.