System.DirectoryServices or System.DirectoryServicesAccountManagement

kouts1 used Ask the Experts™
I'm writing a web application using VB.Net 3.5.  I have everything from modifying Active Directory user properities etc... But I can't figure out how to get a list of AD groups the user belongs to with just the CN.  I need this using system. directory sevices or System.DirectoryServices.AccountManagement.  
I prefer, if possible, any ideas you guys may have be in  
This is what I have that works, but I need to trim the result with just to show the name of the group not the whole DN. I don't need "CN=,OU=, OU=, DC=  . . ."  I just need the CN.  i know I'm missing something being a novice and all.

Dim glUserDN As String
    Dim deUserPath As String
    Dim deUserName As String
    Dim de As New DirectoryEntry("LDAP://")
    Dim iSelected As Integer

Private Sub FindUserGroup()
        Dim deSearch As New DirectorySearcher()
        deSearch.SearchRoot = de

        deSearch.Filter = "(&(objectClass=User) (employeeID=" & txtEmpID.Text.Trim() & "))"

        'Find the Result using FindAll
        Dim results As SearchResultCollection = deSearch.FindAll()
        Dim res As SearchResult
        Dim arl As New ArrayList()
        Dim i As Integer


        If results.Count > 0 Then
            For Each res In results
                For i = 0 To res.Properties("memberOf").Count - 1
                    'Dim vVal As New ListItem()
                    'vVal.Text = res.Properties("cn")(i).ToString()
                    'vVal.Value = res.Properties("memberOf")(i).ToString()
                glUserDN = res.Properties("AdsPath")(0).ToString()

        End If

        'deUser = results(0).GetDirectoryEntry()
        txtUSRPath.Text = results(0).Properties("AdsPath")(0).ToString()
        txtUSRName.Text = results(0).Properties("displayName")(0).ToString() 'deUser.Name

    End Sub

Thank you!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Here is a simple functio to convert you DN's (CN=...,OU=...DC=...) into the Relativ Distinguishe Names (the  pure object names). Please note that we normally have to care about commas and other special characters in the object's name ( - but these shouldn't be existant in AD group names:

    Public Function get_rdn_pure(ByVal distinguishedName As String) As String
        'gives the friendly rdn name without "cn="
        get_rdn_pure = Split(distinguishedName, ",")(0)
        get_rdn_pure = Split(get_rdn_pure , "=")(1)
    End Function


Awesome! Thank you!!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial