Active Directory OU から有効なjqTree JSON 構造を作成する必要があります。これを再帰メソッド(InfoNode)でテストしているのですが、取得できません。
結果の 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);
}
}
}