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")(propertyCounte r), 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
--
Message posted via http://www.dotnetmonster.com