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.
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
Marked as answer by aravind.pk on Mar 06, 2008 06:39 AM
Can you please tell me What is this LDAPpath in this code, I want to fetch all distribution contacts from outlook. Please help me out if you have the code.
Can you please tell me What is this LDAPpath in this code, I want to fetch all distribution contacts from outlook. Please help me out if you have the code.
Thanks
Manish
LDAPPath is your exchangeserver or active directory server path. say,
I don't know about past or future either, but today I'm the most grateful person on the planet to you! Amazing...piece of code working there for me and its all because of a this hinting code of yours !!!
I'm very thankful to you :-)
Though, now I'm more intrigued to get to learn 'mechanics' of Directory Services from .NET Framework.
aravind.pk
Member
241 Points
79 Posts
Displaying Members in a Distribution List
Feb 25, 2008 12:23 PM|LINK
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.
Active Directory outlook distribution list
aravind.pk
Member
241 Points
79 Posts
Re: Displaying Members in a Distribution List
Mar 04, 2008 09:50 AM|LINK
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));
}
}
marafacs
Member
77 Points
51 Posts
MVP
Re: Displaying Members in a Distribution List
Apr 30, 2008 11:21 AM|LINK
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 ?
Mostafa M.Arafa Elzoghbi
C# MVP,MCT,MCSD.Net,MCTS
Follow me on Twitter: @mostafaelzoghbi
aravind.pk
Member
241 Points
79 Posts
Re: Displaying Members in a Distribution List
May 05, 2008 11:35 AM|LINK
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); } }Directory Services DirectoryEntry Active Directory distribution list
marafacs
Member
77 Points
51 Posts
MVP
Re: Displaying Members in a Distribution List
May 05, 2008 01:35 PM|LINK
Thanks man alot, i will try it and let you know if i face any other thing [:D].
Mostafa M.Arafa Elzoghbi
C# MVP,MCT,MCSD.Net,MCTS
Follow me on Twitter: @mostafaelzoghbi
marafacs
Member
77 Points
51 Posts
MVP
Re: Displaying Members in a Distribution List
May 06, 2008 09:28 AM|LINK
it works perfect....Thanks alot man.
Mostafa M.Arafa Elzoghbi
C# MVP,MCT,MCSD.Net,MCTS
Follow me on Twitter: @mostafaelzoghbi
aravind.pk
Member
241 Points
79 Posts
Re: Displaying Members in a Distribution List
May 13, 2008 10:41 AM|LINK
you are welcome :)
manish_manu0...
Member
4 Points
6 Posts
Re: Displaying Members in a Distribution List
Jul 07, 2008 10:05 AM|LINK
Hi,
Can you please tell me What is this LDAPpath in this code, I want to fetch all distribution contacts from outlook. Please help me out if you have the code.
Thanks
Manish
distribution list
aravind.pk
Member
241 Points
79 Posts
Re: Displaying Members in a Distribution List
Jul 15, 2008 04:54 AM|LINK
LDAPPath is your exchangeserver or active directory server path. say,
LDAP Path can be like LDAP://yourserver/DC=youdomain,DC=com"
patelkunala
Member
2 Points
1 Post
Re: Displaying Members in a Distribution List
Feb 25, 2010 01:11 PM|LINK
Hello Sir,
I don't know about past or future either, but today I'm the most grateful person on the planet to you! Amazing...piece of code working there for me and its all because of a this hinting code of yours !!!
I'm very thankful to you :-)
Though, now I'm more intrigued to get to learn 'mechanics' of Directory Services from .NET Framework.
Thanks Again !
Regards,
Kunal Patel
distribution list reading members