system.directoryservices usage

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

I figured I'd start this post on the .NET general forum instead of the
ADSI forum but feel free to nudge me along if I am looking in the wrong
place.

I am working with System.DirectoryServices to connect up to Active
Directory and make a couple of queries. The trouble starts as soon as I
attempt to compile this thing. I receive "Type
'System.DirectoryServices.SearchResultCollection' has no constructors." from
the following code. Since I'm in learning mode I am certain I'm doing
something wrong here. Any ideas where to go with this would be welcome.

Imports System.DirectoryServices

Partial Class companycontact

Inherits System.Web.UI.Page

Const ADConnectionString As String =
"LDAP://tirpitz.home.warnocksolutions.com"

Private Sub test_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles test.Click

Dim oConnection As New DirectoryEntry(ADConnectionString)

Dim oSearcher As New DirectorySearcher(oConnection)

Dim oSearchResults As New SearchResultCollection()

Dim oSearchResult As New SearchResult

oSearcher.Filter = "(objectClass=user)"

oSearchResults = oSearcher.FindAll()

For Each oSearchResult In oSearchResults

output.Text = oSearchResult.Properties("name").ToString

Next

End Sub

End Class
 
Sean,

Change the following line
Dim oSearchResults As New SearchResultCollection()
to
Dim oSearchResults As SearchResultCollection()

HTH, Jakob.
 
Just remove New from the oSearchResults declaration line.

"Sean" <no spam> wrote in message
I figured I'd start this post on the .NET general forum instead of the
ADSI forum but feel free to nudge me along if I am looking in the wrong
place.

I am working with System.DirectoryServices to connect up to Active
Directory and make a couple of queries. The trouble starts as soon as I
attempt to compile this thing. I receive "Type
'System.DirectoryServices.SearchResultCollection' has no constructors." from
the following code. Since I'm in learning mode I am certain I'm doing
something wrong here. Any ideas where to go with this would be welcome.

Imports System.DirectoryServices

Partial Class companycontact

Inherits System.Web.UI.Page

Const ADConnectionString As String =
"LDAP://tirpitz.home.warnocksolutions.com"

Private Sub test_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles test.Click

Dim oConnection As New DirectoryEntry(ADConnectionString)

Dim oSearcher As New DirectorySearcher(oConnection)

Dim oSearchResults As New SearchResultCollection()

Dim oSearchResult As New SearchResult

oSearcher.Filter = "(objectClass=user)"

oSearchResults = oSearcher.FindAll()

For Each oSearchResult In oSearchResults

output.Text = oSearchResult.Properties("name").ToString

Next

End Sub

End Class
 
Thanks guys. Remind me to reread my code in the morning after playing
with this kind of thing at midnight.
 
Back
Top