当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - How to get a list of all users in SharePoint

问题描述:

How to get a list of all users in a certain group in SharePoint by code?

网友答案:
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);
        }
    }
}
网友答案:

i used this first line instead and it worked. thanks dude :)

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/>"));
                }
            }
分享给朋友:
您可能感兴趣的文章:
随机阅读: