Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 620
  • Last Modified:

Populate a dropdownlist with members of a security group in ASP.NET(VB)

I've got a security group called MANAGERS. How would I populate a dropdownlist with the names from this group?
Mike Miller
Mike Miller
  • 4
  • 3
1 Solution
Kyle AbrahamsSenior .Net DeveloperCommented:
Is it an AD group?  If not what group?
Praveen VenuTechnical Project ManagerCommented:

 public static DataSet GetUsersForGroup(string GroupName)
DataSet dsUser = new DataSet();
DirectoryEntry de = GetDirectoryObject();
//create instance fo the direcory searcher
DirectorySearcher deSearch = new DirectorySearcher();
//set the search filter
deSearch.SearchRoot =de;
deSearch.Filter = "(&(objectClass=group)(cn=" + GroupName +"))";
//get the group result
SearchResult results= deSearch.FindOne();
//Create a new table object within the dataset
DataTable tbUser = dsUser.Tables.Add("Users");
//Create default row
DataRow rwDefaultUser = tbUser.NewRow();
rwDefaultUser ["UserName"]= "0";
rwDefaultUser ["DisplayName"]="(Not Specified)";
rwDefaultUser ["EMailAddress"]="(Not Specified)";
//if the group is valid, then continue, otherwise return a blank dataset
if(results !=null)
//create a link to the group object, so we can get the list of members
//within the group
DirectoryEntry deGroup= new DirectoryEntry(results.Path,ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);
//assign a property collection
System.DirectoryServices.PropertyCollection pcoll = deGroup.Properties;
int n = pcoll["member"].Count;
//if there are members fo the group, then get the details and assign to the table
for (int l = 0; l < n ; l++)
//create a link to the user object sot hat the FirstName, LastName and SUername can be gotten
DirectoryEntry deUser= new DirectoryEntry(ADFullPath + "/" +pcoll["member"][l].ToString(),ADAdminUser,ADAdminPassword,AuthenticationTypes.Secure);
//set a new empty row
DataRow rwUser = tbUser.NewRow();
//populate the column
rwUser["UserName"]= GetProperty(deUser,"cn");
rwUser["DisplayName"]= GetProperty(deUser,"givenName") + " " + GetProperty(deUser,"sn");
rwUser["EMailAddress"]= GetProperty(deUser,"mail");
//append the row to the table of the dataset
//close the directory entry object
return dsUser;

Open in new window

Mike MillerSoftware EngineerAuthor Commented:
Yes, an AD group.
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Kyle AbrahamsSenior .Net DeveloperCommented:
Below is the attached VB.Net code.

instead of slGroupMembers.Add you could just add it write to your drop down list.

Public Shared Function GetADS_Group_Members(ByVal strGroup_Name As
String) As SortedList
Dim deGroup As DirectoryEntry
Dim MembersCollection As IADsMembers
Dim member As IADsUser
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim slGroupMembers As New SortedList
deGroup = New DirectoryServices.DirectoryEntry("LDAP://CN=" &
strGroup_Name & ",OU=User Groups,OU=Groups,OU=SOMEOU1,OU=SOMEOU2," &
objRootDSE.Properties("defaultNamingContext")(0).T oString())
MembersCollection = CType(deGroup.Invoke("Members"),
For Each member In MembersCollection
slGroupMembers.Add(member.LastName, Replace(member.Name,
"CN=", "", , , CompareMethod.Text) & "|;|" & member.ADsPath)
Catch ex As Exception
If Not IsNothing(deGroup) Then deGroup.Close()
deGroup = Nothing
End Try
Return slGroupMembers
End Function

Open in new window

Mike MillerSoftware EngineerAuthor Commented:
What's the deal with IADsMembers and IADsUser? What ref/namespace would I use for those?
Kyle AbrahamsSenior .Net DeveloperCommented:

See post November 19th, 2005, 05:32 PM

Imports System
Imports System.DirectoryServices
Imports System.Web.HttpContext
Imports System.Collections
Imports ActiveDs

Mike MillerSoftware EngineerAuthor Commented:
I keep getting Index out of range on the following

deGroup = New DirectoryServices.DirectoryEntry("LDAP://CN=" &
strGroup_Name & ",OU=User Groups,OU=Groups,OU=SOMEOU1,OU=SOMEOU2," &
objRootDSE.Properties("defaultNamingContext")(0).T oString())

Have you actually used this?
Mike MillerSoftware EngineerAuthor Commented:
Nevermind, I got it. I just took off

," &objRootDSE.Properties("defaultNamingContext")(0).ToString()

and it worked fine. Thanks!

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now