Displaying Members in a Distribution List

Rate It (1)

Last post 05-13-2008 6:41 AM by aravind.pk. 6 replies.

Sort Posts:

  • Displaying Members in a Distribution List

    02-25-2008, 8:23 AM
    • Loading...
    • aravind.pk
    • Joined on 02-20-2008, 8:00 AM
    • India
    • Posts 67

    Hi All,

    I need to identify a particular Distribution List is available or not. If it is available, then i need to display the members falling under that distribution List. I need this to be done in asp.net using C#.Net.

    Please provide me sample code of where to change or how to do that? i tried giving in

    search.filter="memberOf=...". But memberOf list contains many fields like CN=..., OU=... like that. Which one to give in Filter so that i can display the members in that Distribution List. 

    How to do that? And also, a code snippet, where i can get user's "memberOf" properties alone seperately. Say, if he a particular user "xyz" is a member of an orgn "ABC" and also under distribution lists of that orgn, say "ABC-Developers" and "ABC-Csharp", then i need to display like "xyz" member of "ABC, ABC-Developers, ABC-CSharp" like that. and in next line, to display the whole list of members falling under those 3 DL's.

    Thanks in advance.

    Aravind
  • Re: Displaying Members in a Distribution List

    03-04-2008, 5:50 AM
    Answer
    • Loading...
    • aravind.pk
    • Joined on 02-20-2008, 8:00 AM
    • India
    • Posts 67

     Atlast, i found myself the answer for my query. hope this might work to solve this issue.

    To display the members falling under the distribution list, here are the steps as i did to get:

    step-1: Use the filter as search.filter = "CN=<DL display or CN property Name>"; 

    step-2: If you read all its properties through
    foreach(Object adObj in SearchObj.FindAll())
    {
        foreach (String objName in adObj.GetDirectoryEntry().Properties["member"])
        {         
                document.write(convert.toString(objName));
        }
    }

    Aravind
  • Re: Displaying Members in a Distribution List

    04-30-2008, 7:21 AM
    • Loading...
    • marafacs
    • Joined on 11-21-2005, 4:32 PM
    • Kuwait
    • Posts 21

     

    Can you post the full code for step 1,2 ?

    How can i want to get members name or email or username while the loop ?

     

    Moustafa M.Arafa
    DotNet Boom Supportive Development Manager
    C# MVP,MCT,MCSD.Net,MCTS
    http://www.dotnetboom.net

  • Re: Displaying Members in a Distribution List

    05-05-2008, 7:35 AM
    • Loading...
    • aravind.pk
    • Joined on 02-20-2008, 8:00 AM
    • India
    • Posts 67

     

    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) + "&lt;Br>";
                        int selIndex = objName.IndexOf("CN=") + 3;
                        int selEnd = objName.IndexOf(",OU") - 3;
                        str1 += objName.Substring(selIndex, selEnd).Replace("\\", "") + "&lt;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);
    
            }
        }
      
    Aravind
  • Re: Displaying Members in a Distribution List

    05-05-2008, 9:35 AM
    • Loading...
    • marafacs
    • Joined on 11-21-2005, 4:32 PM
    • Kuwait
    • Posts 21

    Thanks man alot, i will try it and let you know if i face any other thing   Big Smile.

     

    Moustafa M.Arafa
    DotNet Boom Supportive Development Manager
    C# MVP,MCT,MCSD.Net,MCTS
    http://www.dotnetboom.net

  • Re: Displaying Members in a Distribution List

    05-06-2008, 5:28 AM
    • Loading...
    • marafacs
    • Joined on 11-21-2005, 4:32 PM
    • Kuwait
    • Posts 21

    it works perfect....Thanks alot man.

    Moustafa M.Arafa
    DotNet Boom Supportive Development Manager
    C# MVP,MCT,MCSD.Net,MCTS
    http://www.dotnetboom.net

  • Re: Displaying Members in a Distribution List

    05-13-2008, 6:41 AM
    • Loading...
    • aravind.pk
    • Joined on 02-20-2008, 8:00 AM
    • India
    • Posts 67

    you are welcome :) 

    Aravind
Page 1 of 1 (7 items)