D
Dave
Could someone fix this for me please. The last bit i cant figure out is the
last line in the sub.
Results.SetDataBinding(myTable.DefaultView, "")
Thanks
Dave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Imports System.DirectoryServices
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim strADPath As String
strADPath = "domain.com"
Dim rootEntry As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath,
"Administrator", "password")
Dim searcher As New DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("email")
searcher.PropertiesToLoad.Add("adsPath")
'searcher.PropertiesToLoad.AddRange(New String() {"cn", "mail"})
'would also work and saves you some code
searcher.Filter = ("(&(objectCategory=person)(objectClass=user))")
Dim myTable As New Data.DataTable("Results")
Dim colName As String
For Each colName In searcher.PropertiesToLoad
myTable.Columns.Add(colName, GetType(System.String))
Next
Dim queryResults As SearchResultCollection
queryResults = searcher.FindAll()
Dim result As SearchResult
For Each result In queryResults
Dim dr As Data.DataRow = myTable.NewRow()
For Each colName In searcher.PropertiesToLoad
If result.Properties.Contains(colName) Then
dr(colName) = CStr(result.Properties(colName)(0))
Else
dr(colName) = ""
End If
Next
myTable.Rows.Add(dr)
Next
Results.SetDataBinding(myTable.DefaultView, "")
End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
last line in the sub.
Results.SetDataBinding(myTable.DefaultView, "")
Thanks
Dave
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Imports System.DirectoryServices
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim strADPath As String
strADPath = "domain.com"
Dim rootEntry As DirectoryEntry = New DirectoryEntry("LDAP://" & strADPath,
"Administrator", "password")
Dim searcher As New DirectorySearcher(rootEntry)
searcher.PropertiesToLoad.Add("cn")
searcher.PropertiesToLoad.Add("email")
searcher.PropertiesToLoad.Add("adsPath")
'searcher.PropertiesToLoad.AddRange(New String() {"cn", "mail"})
'would also work and saves you some code
searcher.Filter = ("(&(objectCategory=person)(objectClass=user))")
Dim myTable As New Data.DataTable("Results")
Dim colName As String
For Each colName In searcher.PropertiesToLoad
myTable.Columns.Add(colName, GetType(System.String))
Next
Dim queryResults As SearchResultCollection
queryResults = searcher.FindAll()
Dim result As SearchResult
For Each result In queryResults
Dim dr As Data.DataRow = myTable.NewRow()
For Each colName In searcher.PropertiesToLoad
If result.Properties.Contains(colName) Then
dr(colName) = CStr(result.Properties(colName)(0))
Else
dr(colName) = ""
End If
Next
myTable.Rows.Add(dr)
Next
Results.SetDataBinding(myTable.DefaultView, "")
End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~