.NET Framework Developer Center > .NET Development Forums > .NET Framework Networking and Communication > How to get a efficient way to the Exchange GAL (Global Adress List) with c#
Ask a questionAsk a question
 

QuestionHow to get a efficient way to the Exchange GAL (Global Adress List) with c#

  • Tuesday, November 03, 2009 4:01 PMlittle_Attila Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello,

    I'm trying to get the GAL (Global Adress List) from Exchange to bind the result to a Listbox. My sample (see code) need to much time in large Active Directories. 

    Has anyone an alternative solution (inclusive sample) for this problem that can be speed up the access (Maybe Webdav etc.)

    Thanks,
    little_Attila  

    public ArrayList returngal()
            {
                ArrayList arrGal = null;

                try
                {
                    DirectorySearcher objsearch = new DirectorySearcher();
                    //string strrootdse = objsearch.SearchRoot.Path;

                    DirectoryEntry objdirentry = new DirectoryEntry(LDAP://<URL2LDAP>);
                    objsearch.Filter = "(&(mailNickname=*)(showinaddressbook=*))";
                    objsearch.Filter = textBox1.Text;
                    objsearch.SearchScope = System.DirectoryServices.SearchScope.Subtree;
                    objsearch.PropertiesToLoad.Add("cn");
                    objsearch.PropertyNamesOnly = true;
                    objsearch.Sort.Direction = System.DirectoryServices.SortDirection.Ascending;
                    objsearch.Sort.PropertyName = "cn";
                    objsearch.PageSize = 500;
                    SearchResultCollection colresults = objsearch.FindAll();
                    arrGal = new ArrayList();
                    foreach (SearchResult objresult in colresults)
                    {
                        arrGal.Add(objresult.GetDirectoryEntry().Properties["cn"].Value);
                    }
                    objsearch.Dispose();
                }
                catch (System.Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                return arrGal;
            }

All Replies