日期:2014-05-18  浏览次数:20932 次

如何取活动目录AD中的部门和电话等信息,急求帮助,高分求专家
DirectoryEntry entry = new DirectoryEntry("LDAP://OU=信息技术部,DC=MYCOMPANY", "MYACOUNT", "123456");
//遍历他的所有属性,发现只有只个有限的属性
foreach (string d in entry.Properties.PropertyNames)
{
  string strname = d + ":" + entry.Properties[d].Value;  
  textBox1.Text += strname + "\r\n";
   
}

///然后我又通过查询去动态加载属性,发现COUNT为0,加载不了,我用的账号不是AD管理员的账号会不会有影响?
  DirectorySearcher ds = new DirectorySearcher(entry);
  ds.Filter = "(sAMAccountName=" + "USERA" + ")";
  ds.PropertiesToLoad.Add("cn");
  ds.PropertiesToLoad.Add("sAMAccountName");
  ds.PropertiesToLoad.Add("department");
  ds.PropertiesToLoad.Add("telephoneNumber");
  textBox1.Text += sr.Properties["department"][0].ToString() + "\r\n";
  SearchResult sr = ds.FindOne();

  foreach (string d in sr.Properties.PropertyNames)
  {
  string strname = d + ":" + convert(sr.Properties[d][0]);

  textBox1.Text += strname + "\r\n";

  }

------解决方案--------------------
关注!!
帮你顶!!
------解决方案--------------------
学习一下
------解决方案--------------------
又学习到了.感谢楼主分享