By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,373 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

Enumerate members of a group in codebehind pages...

P: n/a

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)"
Dim groupNames As StringBuilder = New StringBuilder

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))

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.




Message posted via
Nov 19 '05 #1
Share this Question
Share on Google+
2 Replies

P: n/a


Message posted via
Nov 19 '05 #2

P: n/a
> 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.


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

"Steve Oswald via" <fo***> wrote in
message news:55******************************@DotNetMonste


Message posted via

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.