Regarding the email addresses - InfoPath Dev
in

InfoPath Dev

Regarding the email addresses

Last post 05-08-2006 04:25 PM by Greg Collins. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 05-08-2006 02:54 AM

    Regarding the email addresses

    Don't know if I should put this into the old http://www.infopathdev.com/forums/topic.asp?TOPIC_ID=554thread but anyway.

    As I couldn't get it work I came up with another solution. I wrote a small WebService and read all members from a AD group, or better the eMail addresses of them. In my InfoPath document I populate a DDL with theses values using the connection wirzard for WebServices. Not exactly what I wanted to have but still better than nothing.
    The basics I found here http://forums.asp.net/thread/1159654.aspx and I tailored it to my belongings. For those who are interested here is the code I am using for my WebService:

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.DirectoryServices;
    using System.Text;
    using System.Diagnostics;
    using System.Web;
    using System.Xml;
    using System.Web.Services;

    namespace GetADGroupMembers
    {
    public class Service1 : System.Web.Services.WebService
    {
    public Service1()
    {
    InitializeComponent();
    }

    private IContainer components = null;

    private void InitializeComponent()
    {

    }

    protected override void Dispose( bool disposing )
    {
    if(disposing && components != null)
    {
    components.Dispose();
    }
    base.Dispose(disposing);
    }

    //for repeating structure
    public struct MemberMail
    {
    public string eMail;
    }

    [WebMethod]
    public MemberMail[] GetMemberMail()
    {
    MemberMail[] mails = null;


    DirectoryEntry group = new DirectoryEntry(
    "LDAP://CN=ADGroupName,OU=ThirdOU(group is in this OU),OU=SecondOU,OU=TopOU Worldwide,DC=dc1,DC=dc2,DC=dc3", //change this how you need it
    null,
    null,
    AuthenticationTypes.Secure
    );

    StringBuilder sb = new StringBuilder();

    sb.Append("(|");

    using (group)
    {
    foreach (string s in group.Properties["member"])
    {
    sb.AppendFormat("(distinguishedName={0})", s);
    }
    }

    sb.Append(")");

    DirectoryEntry searchRoot = new DirectoryEntry(
    "LDAP://dc=corp,dc=huskyims,dc=com",
    null,
    null,
    AuthenticationTypes.Secure
    );

    using (searchRoot)
    {
    DirectorySearcher ds = new DirectorySearcher(
    searchRoot,
    sb.ToString(),
    new string[]{"mail"} // read here what ever you want e.g. nick samaccountname etc.
    );

    using (SearchResultCollection src = ds.FindAll())
    {
    mails = new MemberMail[src.Count];
    int i = 0;
    foreach (SearchResult sr in src)
    {
    foreach (string key in sr.Properties.PropertyNames)
    {
    if(key == "adspath")
    {
    }
    else
    {
    foreach (object o in sr.Properties[key])
    {
    mails.eMail = o.ToString();
    i++;
    }
    }
    }
    }
    }
    return mails;
    }
    }
    }
    }


    That's it may be someone can use it
    Listen to Motörhead cos they play Rock'n Roll :)
  • 05-08-2006 04:25 PM In reply to

    Re: Regarding the email addresses

    Thanks for sharing this with us!
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.