c# - Autocomplete Text Box With Active Directory Users -


hi there trying create textbox when user types list of users specific name:

example: if started type jane.doe, , had typed in ja list come users active directory start ja. need figure out how can users list each time user types. pretty have ajax side done. getting list of users updated each time.

my current idea:

 [httppost]     public actionresult remotedata(string query)     {         list<string> lstadusers = new list<string>();          using (var context = new principalcontext(contexttype.domain, null, "ldappath"))         {             using (var searcher = new principalsearcher(new userprincipal(context)))             {                 foreach (var result in searcher.findall())                 {                     directoryentry de = result.getunderlyingobject() directoryentry;                      string userswithname;                       if (!string.isnullorempty((string)de.properties["samaccountname"].value))                     {                         userswithname = de.properties["samaccountname"].value.tostring();                            lstadusers.add(userswithname);                     }                  }             }         }          list<string> listdata = null;         if (!string.isnullorempty(query))         {              listdata = lstadusers.where(q => q.tolower().startswith(query.tolower())).tolist();          }             return json(new { data = listdata });     } 

so allows every user in active directory don't want because issue @ hand gets there many users , search takes forever load before displays list of names. want able take parameter , search user starts that. how go doing this?

you need populate name property of userprincipal wildcard limit result set:

// assume 'query' 'ja' userprincipal user = new userprincipal(context); user.name = query + "*"; // builds 'ja*', finds names starting 'ja' using (var searcher = new principalsearcher(user)) // ... 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -