Active Directory OU에서 유효한 jqTree JSON 구조를 만들어야합니다. 이 재귀 메서드 (InfoNode)를 사용하여 테스트 중이지만 가져올 수 없습니다.Active Directory OU 트리 to jqTree
결과 json은 json 문자열로갑니다. 처리 할 첫 번째 노드는 기본 도메인 루트가있는 DirectoryEntry 상위 노드입니다. 재귀 적 메소드 (InfoNode)는 현재 하위 노드 인 을 가져 와서 "OU"로 필터링하고 JSON 속성 인 "label"및 "path"를 만듭니다. 먼저이 노드에 현재 JSON 항목의 끝을 쓸 자식이 더 있는지 검사합니다. 마지막으로 더 많은 자식이있는 경우 다시 (InfoNode) 메서드를 실행하십시오.
public static DirectoryEntry root = new DirectoryEntry("LDAP://RootDSE");
public string dom = (string)root.Properties["defaultNamingContext"].Value;
public string json = "";
public Form1()
{
InitializeComponent();
DirectoryEntry parent = new DirectoryEntry("LDAP://" + dom);
InfoNode(parent);
System.IO.File.WriteAllText(@"json.txt", json);
}
void InfoNode(DirectoryEntry node)
{
string[] arr = node.Name.Split('=');
if (arr[0] == "OU")
{
json += "'children':[{'label':'" + arr[1] + "','path':'" + node.Path + "'";
if (nodo.Children == null)
{
json += "}]";
}
else
{
json += ",";
}
}
if (node.Children != null)
{
foreach (DirectoryEntry child in node.Children)
{
InfoNode(child);
}
}
}