感谢 marc_s 回来。
我尝试了以下代码:
public void GetInfo()
{
try
{
//Object obj;
DirectorySearcher search;
DirectoryEntry entry;
SearchResult result;
String mailid = "";
bool flag = false;
entry = new DirectoryEntry(LDAPpath);//, Domainwithuser, password);
search = new DirectorySearcher(entry);
search.Filter = "CN=DistributionList1";
int i = search.Filter.Length;
string str = "", str1 = "";
foreach (SearchResult AdObj in search.FindAll())
{
foreach (String objName in AdObj.GetDirectoryEntry().Properties["member"])
{
str += Convert.ToString(objName) + "<Br>";
int selIndex = objName.IndexOf("CN=") + 3;
int selEnd = objName.IndexOf(",OU") - 3;
str1 += objName.Substring(selIndex, selEnd).Replace("\\", "") + "<BR>";
DirectorySearcher dsSearch = new DirectorySearcher(entry);
dsSearch.Filter = "CN=" + objName.Substring(selIndex, selEnd).Replace("\\", "");
foreach (SearchResult rs in dsSearch.FindAll())
{
str1 += "<p align='right'><font face='calibri' color='#2266aa' size=2>" + Convert.ToString(rs.GetDirectoryEntry().Properties["mail"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["displayName"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["sAMAccountName"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["department"].Value) + "|" + Convert.ToString(rs.GetDirectoryEntry().Properties["memberOf"].Value) + "</font></p>";
}
}
}
Response.Write("<BR>" + str + "<Br>" + str1 + "<BR>");
}
catch (Exception ex)
{
Response.Write("--unable to fetch--<BR>" + ex.Message);
}
}
在这里,search.findAll
抛出一个DirectoryCOMException
说法
语法中的无效 dn
我需要获取属于分发列表的所有电子邮件地址。
我确实尝试实施以下链接中详述的方法,但不幸的是它不起作用: https ://forums.asp.net/t/1224607.aspx?Displaying+Members+in+a+Distribution+List
任何帮助表示赞赏。
谢谢。