Q: a function

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.
 
S

Steve C. Orr [MVP, MCSD]

public string ReadADUserGROUPX(string userName)
{
string ReadADUserGROUPX_temp = null;
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://DC=domain,DC=com");
DirectorySearcher searcher = new DirectorySearcher(rootEntry);

// set return value to nothing
ReadADUserGROUPX_temp = "";
searcher.Filter = "(&(anr=" + userName + ")(objectCategory=person))";
searcher.PropertiesToLoad.Add("");
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("memberof");

SearchResult sResult = searcher.FindOne();

if (sResult != null)
{
ResultPropertyCollection propColl = null;
propColl = sResult.Properties;
foreach (string pKey in propColl.PropertyNames)
{
foreach (object pCollection in propColl[pKey])
{
if (pKey.ToUpper() == "MEMBEROF" & pCollection.ToUpper() Like)
{
"CN=GROUPX_*" Then;
ReadADUserGROUPX_temp = pCollection.ToString().Substring(11 - 1, 3);
return ReadADUserGROUPX_temp;
}
}
}
}
return ReadADUserGROUPX_temp;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top