G
Guest
Hello,
I have this function working in one of my project. Can anyone convert this
to C#? I used one of the converter but faced problems, it did not compile.
Public Function ReadADUserGROUPX(ByVal userName As String) As String
Dim rootEntry As New DirectoryEntry("LDAP://DC=domain,DC=com")
Dim searcher As New DirectorySearcher(rootEntry)
' set return value to nothing
ReadADUserGROUPX = ""
searcher.Filter = "(&(anr=" & userName & ")(objectCategory=person))"
searcher.PropertiesToLoad.Add("")
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("memberof")
Dim sResult As SearchResult = searcher.FindOne
If Not (sResult Is Nothing) Then
Dim propColl As ResultPropertyCollection
propColl = sResult.Properties
Dim pKey As String
For Each pKey In propColl.PropertyNames
Dim pCollection As Object
For Each pCollection In propColl(pKey)
'tbEmpManagerEMail.Text &= (pKey & "=" & pCollection) &
vbCrLf ' all the collection will be shown
If UCase(pKey) = "MEMBEROF" And UCase(pCollection) Like
"CN=GROUPX_*" Then
ReadADUserGROUPX = Mid(pCollection, 11, 3)
Return ReadADUserGROUPX
End If
Next pCollection
Next pKey
End If
Return ReadADUserGROUPX
End Function
Thanks,
Jim.
I have this function working in one of my project. Can anyone convert this
to C#? I used one of the converter but faced problems, it did not compile.
Public Function ReadADUserGROUPX(ByVal userName As String) As String
Dim rootEntry As New DirectoryEntry("LDAP://DC=domain,DC=com")
Dim searcher As New DirectorySearcher(rootEntry)
' set return value to nothing
ReadADUserGROUPX = ""
searcher.Filter = "(&(anr=" & userName & ")(objectCategory=person))"
searcher.PropertiesToLoad.Add("")
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("memberof")
Dim sResult As SearchResult = searcher.FindOne
If Not (sResult Is Nothing) Then
Dim propColl As ResultPropertyCollection
propColl = sResult.Properties
Dim pKey As String
For Each pKey In propColl.PropertyNames
Dim pCollection As Object
For Each pCollection In propColl(pKey)
'tbEmpManagerEMail.Text &= (pKey & "=" & pCollection) &
vbCrLf ' all the collection will be shown
If UCase(pKey) = "MEMBEROF" And UCase(pCollection) Like
"CN=GROUPX_*" Then
ReadADUserGROUPX = Mid(pCollection, 11, 3)
Return ReadADUserGROUPX
End If
Next pCollection
Next pKey
End If
Return ReadADUserGROUPX
End Function
Thanks,
Jim.