MOSS 2007 - Get Users From SharePoint Group



Get Users from SharePoint Group and Bind to DropDownList

  //strRole is the GroupName in SharePoint
 public DataTable GetUsersInAGroup(string strManagerRole)
        {
              // Create new DataTable.
            DataTable table = new DataTable("table");

            // Declare DataColumn and DataRow variables.
            DataColumn column,columnEmail;
            DataRow row;

            // Create column.
            column = new DataColumn();
            column.DataType = Type.GetType("System.String");
            column.ColumnName = "Name";
            columnEmail = new DataColumn();
            columnEmail.DataType = Type.GetType("System.String");
            columnEmail.ColumnName = "Email";
            table.Columns.Add(column);
            table.Columns.Add(columnEmail);
//Get users and return as datatable
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                SPUserCollection userCollection = SPContext.Current.Web.Groups[strManagerRole].Users;
                foreach (SPUser user in userCollection)
                {
                      row = table.NewRow();
                    row["Name"] = user.LoginName.Split(':')[1];
                    row["Email"] = user.Email;
                    table.Rows.Add(row);
                                        
                }
            });
                      
            return table;
        }

Bind Users of a SharePoint Group to DropDownList

//Pass the Group name and DropDownlistID
private void BindReportingManagers(DropDownList ddlSecManager,string strManagerRole)
        {
        DataTable table = GetUsersInAGroup(strManagerRole);
        ddlSecManager.DataSource = table;

        ddlSecManager.DataTextField = table.Columns[0].ToString();
        ddlSecManager.DataValueField = table.Columns[1].ToString();
        ddlSecManager.DataBind();
        }

Share |

 Cant find the page you are looking for?
 Help us to improve by adding the content that you are looking for.
 Leave a feedback
 We look forward to hear your comments and feedback.