문제

I wrote a Program that get Data from the Active Directory and I need a LDAP filter that filter the Data to l (city) Parameter.

My Code:

public void SearchByCity(string city)
        {
                                                         //What I must do :(
            DirectoryEntry Entry = new DirectoryEntry("LDAP://<l= + city + >");
            string filter = "(&(objectClass=user)(objectCategory=person)(cn=*))";
            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

            var q = from s in Searcher.FindAll().OfType<SearchResult>()
                    select new
                    {
                        Benutzer = GetProperty(s, "sAMAccountName"),
                        eMail = GetProperty(s, "mail"),
                        Vorname = GetProperty(s, "givenName"),
                        Nachname = GetProperty(s, "sn"),
                        Telefon = GetProperty(s, "telephoneNumber"),
                        UserID = s.GetDirectoryEntry().Guid
                    };

            this.myListView.DataSource = q;
            this.myListView.DataBind();
        }

tarasov

도움이 되었습니까?

해결책

The Solition:

public void SearchByPlace(string city)
        {
            DirectoryEntry Entry = new DirectoryEntry("LDAP://" + Properties.Settings.Default.Domain);
            string filter = "(&(objectClass=user)(objectCategory=person)(l=" + city + ")(cn=*))";
            DirectorySearcher Searcher = new DirectorySearcher(Entry, filter);

            var q = from s in Searcher.FindAll().OfType<SearchResult>()
                    select new
                    {
                        Benutzer = GetProperty(s, "sAMAccountName"),
                        eMail = GetProperty(s, "mail"),
                        Vorname = GetProperty(s, "givenName"),
                        Nachname = GetProperty(s, "sn"),
                        Telefon = GetProperty(s, "telephoneNumber"),
                        UserID = s.GetDirectoryEntry().Guid
                    };

            this.myListView.DataSource = q;
            this.myListView.DataBind();
        }

다른 팁

use this filter

(&(objectCategory=person)(objectClass=user)(!sAMAccountType=805306370)(l=yourcity))
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top