locked
Index was outside the bounds of the array RRS feed

  • Question

  • Hi,

    I’m working on sending mail functionality in my web application. As per my requirement, I need to get emailID and employee name from Active Directory by passing employeeID.

    This is working fine in development environment, but after creating installer its throwing error.

    Error message : Index was outside the bounds of the array.

    It’s not getting emailID and employee name from the active directory.

    This is the code for getting emailID and employee name from the active directory.

     

    public static string GetMailIDAndNameFromEmployeeID(string MID)

        {

            string emailID = "";

            string employeeName = "";

            try

            {

                DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://DC=mindtree,DC=com");

                string adFilterExpression = "SAMAccountName=" + MID.Trim();

                string[] properties = new string[7] { "mail", "memberof", "givenname", "sn", "displayname", "department", "telephonenumber" };

                ResultPropertyCollection propcoll = null;

                DirectorySearcher objSearch = new DirectorySearcher(directoryEntry, adFilterExpression, properties);

                SearchResultCollection result = objSearch.FindAll();

                foreach (SearchResult res in result)

                {

                    propcoll = res.Properties;

                    foreach (string key in propcoll.PropertyNames)

                    {

                      

                        if (key == "mail")

                        {

                            foreach (object values in propcoll[key])

                            {

                                emailID = values.ToString();

                            }

                        }

                        if (key == "displayname")

                        {

                            foreach (object values in propcoll[key])

                            {

                                employeeName = values.ToString();

                            }

                        }

                    }

     

                }

     

            }

            catch (Exception ex)

            {

                return string.Empty;

            }

            return emailID + "," + employeeName;

        }

    }

     

    If anybody knows what is the problem, please let me know.

    • Moved by Ruiz Yi Wednesday, December 2, 2009 3:05 AM Not a TFS Question (From:Team Foundation Server - Team System Web Access)
    Tuesday, December 1, 2009 9:01 AM

All replies