Retrieving members from a DL in LDAP using C#
<p>Thanks marc_s for getting back.</p>

<p>I tried the following code:</p>

<pre><code>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) + "&amp;lt;Br&gt;";
                int selIndex = objName.IndexOf("CN=") + 3;
                int selEnd = objName.IndexOf(",OU") - 3;
                str1 += objName.Substring(selIndex, selEnd).Replace("\\", "") + "&amp;lt;BR&gt;";

                DirectorySearcher dsSearch = new DirectorySearcher(entry);
                dsSearch.Filter = "CN=" + objName.Substring(selIndex, selEnd).Replace("\\", "");

                foreach (SearchResult rs in dsSearch.FindAll())
                {
                    str1 += "&amp;lt;p align='right'&gt;&lt;font face='calibri' color='#2266aa' size=2&gt;" + 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) + "&amp;lt;/font&gt;&lt;/p&gt;";
                }
            }
        }

        Response.Write("&amp;lt;BR&gt;" + str + "&amp;lt;Br&gt;" + str1 + "&amp;lt;BR&gt;");
    }
    catch (Exception ex)
    {
        Response.Write("--unable to fetch--&lt;BR&gt;" + ex.Message);
    }
}
</code></pre>

<p>Here, <code>search.findAll</code> throws a <code>DirectoryCOMException</code> saying </p>

<blockquote>
  <p>invalid dn in syntax</p>
</blockquote>

<p>I have a requirement to fetch all the email addresses that belong to a distribution list.</p>

<p>I did try implementing the approach detailed out in the below link but unfortunately it didn't work:
<a href="https://forums.asp.net/t/1224607.aspx?Displaying+Members+in+a+Distribution+List" rel="nofollow">https://forums.asp.net/t/1224607.aspx?Displaying+Members+in+a+Distribution+List</a></p>

<p>Any help is appreciated.</p>

<p>Thanks.</p>