Get All users from SharePoint Group - Server Side


public SPFieldUserValueCollection GetBODSUser(SPSite osite, SPWeb oweb, SPListItem oItem, string Requestor)
        {
            SPFieldUserValueCollection collection = new SPFieldUserValueCollection();
            string currentuser = oweb.CurrentUser.Name;
            string sendTo = string.Empty;
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(osite.Url))
                    {
                        using (SPWeb objweb = site.OpenWeb())
                        {

                            SPUserCollection ouserCollection = objweb.Groups["HexaCorp BOD"].Users;     //Group
                            foreach (SPUser oUser in ouserCollection)
                            {
                                if (oUser.Name != null && oUser.Name != "")
                                {
                                        SPFieldUserValue value = new SPFieldUserValue(objweb, oUser.ID, oUser.LoginName);
                                        if (value != null)
                                            collection.Add(value);
                                }

                            }
                        }
                    }
                });
            }
            catch (Exception ex)
            {

            }
            return collection;
        }
    }
}

Comments