Salve a tutti,
sono alle prime armi con VB.NET e dovrei popolare un dataset o un datatable con una query fatta su LDAP (Active Directory) che restituisce il nome (valori del campo "cn") e il numero di telefono (valori del campo "TelephoneNumber") di tutti gli utenti del dominio locale..
ho creato la connessione e funziona ma non so come strutturare la query..
qualcuno ha qualchè idea??
i campi su LDAP (Active Directory) sono: "sn" per il nome e "TelephoneNumber" per il telefono..
per ora ho fatto così, ma non capisco il perché genera errore in *** dicendo che l'indice "(0)" è andato oltre il range..
Public Function GetPhoneUsers() As DataTable
' get list of active directory users
' setting up the lookup to AD
Dim adEntry As New DirectoryEntry _
("LDAP://myserver.mydomain.com/DC=mydomain,DC=com")
' define which fields to retrieve from AD
Dim adSearcher As New DirectorySearcher(adEntry)
adSearcher.Filter = "(&(objectCategory=person)(objectClass=user))"
adSearcher.PropertiesToLoad.Add("cn")
adSearcher.PropertiesToLoad.Add("TelephoneNumber")
' define a datatable and add the results to it
Dim adResults As SearchResultCollection
Dim dt As New DataTable("AD_Users")
dt.Columns.Add(New DataColumn("Name", GetType(System.String)))
dt.Columns.Add(New DataColumn("TelephoneNumber", GetType(System.String)))
Dim dr As DataRow
adResults = adSearcher.FindAll
For Each adResult As SearchResult In adResults
' add the results to the datatable
dr = dt.NewRow()
dr(0) = adResult.Properties("cn")(0).ToString()
'***dr(1) = adResult.Properties("TelephoneNumber")(0).ToString()
dt.Rows.Add(dr)
Next
Return dt
End Function
Grazie mille.