private void SelectListItem(int index)
        {
            if (index >= 0 && index < FilteredUsers.Count)
            {
                // kopieer geselecteerde gebruiker
                User u = new User();
                u = FilteredUsers[index];

                // toon naam
                lblGebruiker.Text = u.DisplayName;

                if (u.Dienst == string.Empty)
                    lblDienst.Text = u.Functie;
                else
                    lblDienst.Text = u.Dienst;

                if (u.TelefoonWerk == string.Empty)
                    txtTelefoon.Text = string.Empty;
                else
                    txtTelefoon.Text = u.TelefoonWerk;

                txtTelefoon.Text =  u.TelefoonWerk;
                txtGSM.Text = u.Mobiel;

                lblMailTo.Text = u.Email.ToLower();
                //txtBeschrijving.Text = u.Info;
                //txtGeslacht.Text = u.Geslacht;
            }
            else
            {
                lblGebruiker.Text = string.Empty;
                lblDienst.Text = string.Empty;
                txtTelefoon.Text = string.Empty;
                txtGSM.Text = string.Empty;
                lblMailTo.Text = string.Empty;
            }
        }
Exemple #2
0
        public static List<User> GetUsers(string DomainPath)
        {
            List<User> lstADUsers = new List<User>();
            try
            {
                DirectoryEntry searchRoot = new DirectoryEntry(DomainPath);
                DirectorySearcher search = new DirectorySearcher(searchRoot);
                search.Filter = "(&(objectClass=user)(objectCategory=person))";

                // mailinfo
                search.PropertiesToLoad.Add("samaccountname");
                search.PropertiesToLoad.Add("mail");
                search.PropertiesToLoad.Add("usergroup");
                search.PropertiesToLoad.Add("displayname");
                // search.PropertiesToLoad.Add("mailNickname");

                // gebruikersinfo
                //search.PropertiesToLoad.Add("givenName");                   // voornaam
                //search.PropertiesToLoad.Add("SN");                          // achternaam

                search.PropertiesToLoad.Add("title");                       // functie binnen bedrijf
                search.PropertiesToLoad.Add("description");                 // beschrijving gebruiker
                //search.PropertiesToLoad.Add("manager");                     // LDAP van diensthoofd
                // dienstinfo
                //search.PropertiesToLoad.Add("company");                     // bedrijf
                //search.PropertiesToLoad.Add("department");                  // afdeling
                search.PropertiesToLoad.Add("physicalDeliveryOfficeName");      // dienst
                search.PropertiesToLoad.Add("extensionAttribute1");             // geslacht

                // telefooninfo
                search.PropertiesToLoad.Add("telephoneNumber");             // telefoon werk
                //search.PropertiesToLoad.Add("homePhone");                   // telefoon werk
                search.PropertiesToLoad.Add("mobile");                      // gsm nummer
                search.PropertiesToLoad.Add("facsimileTelephoneNumber");    // fax
                search.PropertiesToLoad.Add("info");                        // telefoon opmerking

                SearchResult result;
                SearchResultCollection resultCol = search.FindAll();
                if (resultCol != null)
                {
                    for (int counter = 0; counter < resultCol.Count; counter++)
                    {
                        string UserNameEmailString = string.Empty;
                        result = resultCol[counter];
                        if (result.Properties.Contains("displayname") &&
                            result.Properties.Contains("telephoneNumber") || result.Properties.Contains("mobile"))
                        {
                            User u = new User();

                            u.DisplayName = (String)result.Properties["displayname"][0];

                            if (result.Properties.Contains("samaccountname"))
                                u.Account = (String)result.Properties["samaccountname"][0];
                            else
                                u.Account = "";

                            if (result.Properties.Contains("mail"))
                                u.Email = (String)result.Properties["mail"][0];
                            else
                                u.Email = "";

                            if (result.Properties.Contains("extensionAttribute1"))
                                u.Geslacht = (String)result.Properties["extensionAttribute1"][0];
                            else
                                u.Geslacht = "";

                            if (result.Properties.Contains("physicalDeliveryOfficeName"))
                                u.Dienst = (String)result.Properties["physicalDeliveryOfficeName"][0];
                            else
                                u.Dienst = "";

                            if (result.Properties.Contains("mobile"))
                                u.Mobiel = (String)result.Properties["mobile"][0];
                            else
                                u.Mobiel = "";

                            if (result.Properties.Contains("description"))
                                u.Beschrijving = (String)result.Properties["description"][0];
                            else
                                u.Beschrijving = "";

                            if (result.Properties.Contains("info"))
                                u.Info = (String)result.Properties["info"][0];
                            else
                                u.Info = "";

                            if (result.Properties.Contains("facsimileTelephoneNumber"))
                                u.Fax = (String)result.Properties["facsimileTelephoneNumber"][0];
                            else
                                u.Fax = "";

                            if (result.Properties.Contains("title"))
                                u.Functie = (String)result.Properties["title"][0];
                            else
                                u.Functie = "";

                            // u.Usergroup = (String)result.Properties["usergroup"][0];
                            //u.Voornaam = (String)result.Properties["givenname"][0];
                            //u.Achternaam = (String)result.Properties["SN"][0];
                            //u.Functie = (String)result.Properties["title"][0];
                            //u.Diensthoofd = (String)result.Properties["Manager"][0];
                            //u.Bedrijf = (String)result.Properties["company"][0];

                            if (result.Properties.Contains("telephoneNumber"))
                                u.TelefoonWerk = (String)result.Properties["telephoneNumber"][0];
                            else
                                u.TelefoonWerk = "";
                            //u.TelefoonThuis = (String)result.Properties["homePhone"][0];

                            lstADUsers.Add(u);
                        }
                    }
                }
                return lstADUsers;
            }
            catch (Exception ex)
            {
                return null;
            }
        }