none
Get Users from Distribution List RRS feed

  • Question

  • Hello Guys,

    I need to retrieve users from distribution list. Is there anyway to get the user from distributed list. Can anyone suggest me the way?

    Thanks,

    Navas 

    Friday, February 21, 2020 9:38 AM

All replies

  • You can use Linq to query a list and get an item out of the list.

    https://www.tutorialsteacher.com/linq/linq-tutorials

    Friday, February 21, 2020 2:12 PM
  • 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 += "&lt;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) + "&lt;/font></p>";
                        }
                    }
                }
                Response.Write("&lt;BR>" + str + "&lt;Br>" + str1 + "&lt;BR>");
            }
            catch (Exception ex)
            {
                Response.Write("--unable to fetch--<BR>" + ex.Message);
    
    
            }
    
    }


    Saturday, February 22, 2020 7:12 AM