我创建了一个类,其中包含一种方法来显示AD中所选用户的属性。当我尝试调用此方法将所有对象放入列表视图时,出现错误。
感谢您的帮助
class ProgramDisplayObjAD
{
public static List<string> ComputersDisAD(string SelectedObjAD)
{
List<string> ComputerNamesList = new List<string>();
DirectoryEntry DirEntry = new DirectoryEntry("LDAP://OU=Backoffice,OU=BIO,DC=bio,DC=corpnet1,DC=com");
DirectorySearcher MySearcher = new DirectorySearcher(DirEntry);
MySearcher.Filter = "(&(objectCategory=computer)(cn=" + SelectedObjAD + "))";
foreach (SearchResult MyResult in MySearcher.FindAll())
{
DirectoryEntry ComputerName = MyResult.GetDirectoryEntry();
Console.WriteLine("Computername : " + ComputerName.Properties["dNSHostName"].Value);
Console.WriteLine("Staging Date : " + ComputerName.Properties["whenCreated"].Value);
Console.WriteLine("Operating System : " + ComputerName.Properties["operatingSystem"].Value);
}
DirEntry.Close();
DirEntry.Dispose();
MySearcher.Dispose();
return ComputerNamesList;
}
private void ListObjAD_DoubleClick(object sender, EventArgs e)
{
string SelectedObjAD = ListObjAD.SelectedItem.ToString();
if (ComputerName.Checked)
{
ComputerPage.Text = SelectedObjAD;
DisplayObjAD.SelectedTab = ComputerPage;
//List<string> ComputersList = ProgramDisplayObjAD.ComputersDisAD(SelectedObjAD);
ComputerItemList.Items.Add(new ListViewItem(new string[] { ProgramDisplayObjAD.ComputersDisAD(SelectedObjAD) };
}
我知道该方法可以正常工作,但是我不知道如何在我的listviewitem中显示结果:ComputerListDis。