My goal is to retrieve the OU names from an LDAP directory and according to each OU name display its sub OU. All this in C# with a WPF interface. My OU retrieval function is ok but the problem is with the display function of the sub OUs according to the chosen OU. I use a global variable and I think the problem comes from there but I don't really know why. If you know why I'm in :) I am available for any question. Thanks
Maxime
There is the code :
namespace WpfApp1
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
comboBoxEntite.ItemsSource = OUList;
afficherOuEntite();
comboBoxSousEntite.ItemsSource = subOuList;
afficherOuSousEntite();
}
private void btnMinimize_Click(object sender, RoutedEventArgs e)
{
WindowState = WindowState.Minimized;
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
Application.Current.Shutdown();
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
DragMove();
}
public void ComboBoxEntite_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
selectedItemF = "LDAP://myserver.lan/OU=" + comboBoxEntite.SelectedItem.ToString() + ",OU=MPG-Users,DC=myserver,DC=lan";
TB.Text = selectedItemF;
}
public void afficherOuEntite()
{
string ldapServer = "LDAP://myserver.lan/OU=MPG-Users,DC=myserver,DC=lan";
DirectoryEntry myLdapConnection = new DirectoryEntry(ldapServer);
DirectorySearcher myDirectorySearcher = new DirectorySearcher(myLdapConnection);
myDirectorySearcher.Filter = "(objectClass=organizationalUnit)";
myDirectorySearcher.PropertiesToLoad.Add("Name");
myDirectorySearcher.SearchScope = SearchScope.OneLevel;
SearchResultCollection resultsOuEntite = myDirectorySearcher.FindAll();
foreach (SearchResult result in resultsOuEntite)
{
string ouName = result.Properties["Name"][0].ToString();
OUList.Add(ouName);
}
}
public void afficherOuSousEntite()
{
DirectoryEntry myLdapConnection = new DirectoryEntry(selectedItemF);
DirectorySearcher myDirectorySearcher = new DirectorySearcher(myLdapConnection);
myDirectorySearcher.Filter = "(objectClass=organizationalUnit)";
myDirectorySearcher.PropertiesToLoad.Add("Name");
myDirectorySearcher.SearchScope = SearchScope.OneLevel;
SearchResultCollection resultsOuSousEntite = myDirectorySearcher.FindAll();
foreach (SearchResult result in resultsOuSousEntite)
{
string ouName = result.Properties["Name"][0].ToString();
subOuList.Add(ouName);
}
}
public List<string> OUList = new List<string>();
public List<string> subOuList = new List<string>();
public static string selectedItemF;
}
}
The result I have concerning the sub-OR is an empty result, as if the search was not based on anything