如何获取SharePoint中所有用户的列表

时间:2009-08-12 14:07:02

标签: c# sharepoint

如何按代码获取SharePoint中某个组中所有用户的列表?

2 个答案:

答案 0 :(得分:11)

using (SPWeb oWebsite = SPContext.Current.Site.OpenWeb("Website_URL"))
{
    SPGroupCollection collGroups = oWebsite.Groups;
    foreach (SPGroup oGroup in collGroups)
    {
        foreach(SPUser oUser in oGroup.Users)
        {
           Response.Write(oUser.Name);
        }
    }
}

答案 1 :(得分:6)

我使用了第一行而且它有效。谢谢老兄:)

SPGroupCollection collGroups = SPContext.Current.Web.Groups;

 foreach (SPGroup oGroup in collGroups)
                {
                    foreach (SPUser oUser in oGroup.Users)
                    {
                        Response.Write(oUser.Name);

                    Label l = new Label();
                    l.Text = oUser.Name;

                    PlaceHolderContents.Controls.Add(l);
                    PlaceHolderContents.Controls.Add(new LiteralControl("<br/>"));
                }
            }