ด้านล่างนี้คือโค้ดที่ใช้อยู่แต่มันจะต้องระบุพารามิเตอร์ดังเช่น OU=Department ผลลัพธ์จะได้เฉพาะคนที่อยู่ใน OU=Department และหากระบุ DC=xxx ก็จะได้ทุกคนที่อยู่ใน DC=xxx ครับ แต่หากผมต้องการได้เฉพาะว่า DC=xxx มี OU อะไรบ้างทำไงครับ อีกอย่างในแต่ละ CN=user,OU=Department ,DC=xxx นั้นหากผมต้องการหาว่าข้อมูลที่เก็บใน attribute เช่น department , tel,employeeid จะเขียนอย่างไรครับ คุณเป้ ขอบคุณครับ
[WebMethod]
public ArrayList EnumerateOU(string OuDn)
{
ArrayList alObjects = new ArrayList();
try
{
DirectoryEntry directoryObject = new DirectoryEntry("LDAP://" + OuDn,"user","pass");
foreach (DirectoryEntry child in directoryObject.Children)
{
string childPath = child.Path.ToString();
alObjects.Add(childPath.Remove(0,27));
//remove the LDAP prefix from the path
child.Close();
child.Dispose();
}
directoryObject.Close();
directoryObject.Dispose();
}
catch (Exception e)
{
Console.WriteLine("An Error Occurred: " + e.Message.ToString());
}
return alObjects;
}