Question : System.DirectoryServices or System.DirectoryServicesAc<wbr />countManag<wbr />ement

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 vb.net.  
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() & "))"
        deSearch.PropertiesToLoad.Add("memberOf")
        deSearch.PropertiesToLoad.Add("cn")

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

        lstMemberOF.Items.Clear()

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

        End If


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


        results.Dispose()
        deSearch.Dispose()
    End Sub

Thank you!

Answer : System.DirectoryServices or System.DirectoryServicesAc<wbr />countManag<wbr />ement

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 (http://www.selfadsi.org/ldap-path.htm#Comma) - 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
Random Solutions  
 
programming4us programming4us