I want to get the email property from the group selected. These are distribution groups. How can I get that? Here is my code..
Code:private void Page_Load(object sender, System.EventArgs e) { DirectoryEntry de = new DirectoryEntry("LDAP://OU=Distribution Lists,DC=CRAB,DC=ORG"); foreach(DirectoryEntry child in de.Children) { ddGroups.Items.Add(child.Name.ToString()); } } #region Web Form Designer generated code override protected void OnInit(EventArgs e) { // // CODEGEN: This call is required by the ASP.NET Web Form Designer. // InitializeComponent(); base.OnInit(e); } /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.ddGroups.SelectedIndexChanged += new System.EventHandler(this.ddGroups_SelectedIndexChanged); this.Load += new System.EventHandler(this.Page_Load); } #endregion private void ddGroups_SelectedIndexChanged(object sender, System.EventArgs e) { string grp = ddGroups.SelectedItem.Text; string grpLeft = grp.Substring(3); int i = 0; DirectoryEntry de = new DirectoryEntry("LDAP://OU=Distribution Lists,DC=CRAB,DC=ORG"); DirectorySearcher srch = new DirectorySearcher("(CN=" + grpLeft + ")"); SearchResultCollection coll = srch.FindAll(); foreach (SearchResult rs in coll) { ResultPropertyCollection resultPropColl = rs.Properties; if(resultPropColl["member"] != null) { foreach( Object memberColl in resultPropColl["member"]) { i = i + 1; DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl); System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties; members = members + i + ". <a href=mailto:" + userProps["sAMAccountName"].Value + "@crab.org>" + userProps["displayName"].Value + "<br></a>"; //Response.Write(userProps["sAMAccountName"].Value); //Response.Write("<br>"); // DirectoryEntry gpMemberEntry = new DirectoryEntry("LDAP://" + memberColl); // System.DirectoryServices.PropertyCollection userProps = gpMemberEntry.Properties; // object obVal = userProps["sAMAccountName"].Value; // if (null != obVal) // { // groupMemebers.Add(obVal.ToString()); // } } } else { members = "<b>No users in this group.</b>"; } } this.DataBind(); } }


Reply With Quote