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

Ahm*_*rid 7 c# sharepoint

如何通过代码获取SharePoint中特定组中的所有用户的列表?

小智 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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)


Ahm*_*rid 7

我使用了第一行而且它有效.多谢,伙计 :)

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/>"));
                }
            }
Run Code Online (Sandbox Code Playgroud)