Enumerate members of a group in vb.net codebehind pages...

  • Thread starter Steve Oswald via DotNetMonster.com
  • Start date
S

Steve Oswald via DotNetMonster.com

Hello!

I need to get a list of all members of a specific group (whether or not the currently logged-in user is a member of that group) in a VB.NET codebehind page.

I am able to get all the information on the currently logged-in user (full name, phone number, e-mail address, etc.), but I cannot get my head around the filters needed to get membership in a group.

Here is what I have so far:

Public Function GetSalesGroup()
Dim search As DirectorySearcher = New DirectorySearcher(_path)
search.Filter = "(cn=Sales)"
search.PropertiesToLoad.Add("group")
Dim groupNames As StringBuilder = New StringBuilder

Try
Dim result As SearchResult = search.FindOne()
Dim propertyCount As Integer = result.Properties("memberOf").Count

Dim dn As String
Dim equalsIndex, commaIndex

Dim propertyCounter As Integer

For propertyCounter = 0 To propertyCount - 1
dn = CType(result.Properties("memberOf")(propertyCounter), String)

equalsIndex = dn.IndexOf("=", 1)
commaIndex = dn.IndexOf(",", 1)
If (equalsIndex = -1) Then
Return Nothing
End If

groupNames.Append(dn.Substring((equalsIndex + 1), (commaIndex - equalsIndex) - 1))
groupNames.Append("|")
Next

Catch ex As Exception
Throw New Exception("Error obtaining Sales group membership. " & ex.Message & "<br>")
End Try

Return groupNames.ToString()
End Function

The results of this are supposed to be thrown to a session variable upon return.

Help!

Thanks!

SteveO
 
K

Kevin Spencer

Anyone?

I'm anyone!

BTW, that's "bump," and it really helps to repeat the question for those of
us that hide read messages in our newsgroup client.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top