Solved

vb.net add ldap query results to listview

Posted on 2014-10-28
3
364 Views
Last Modified: 2014-10-28
I have an ldap query i run via a vb.net gui.  What i am trying to do is return each result to its respective listview column.  Via the below code, the first thing i do is create the two columns.  When i try and run the query nothing appends to its respective column.  If i remove the columing the query works fine, can someone help?

   
Dim item As ListViewItem = ListView1.Items.Add("Username")
        Dim item1 As ListViewItem = ListView1.Items.Add("Title")
        For Each i As String In ListBox1.Items
            Dim de As New DirectoryEntry("LDAP://test.com/DC=test,DC=com")
            Dim LdapFilter As String = "(sAMAccountName=" & i & ")"
            Dim searcher As New DirectorySearcher(de, LdapFilter)
            Dim result As SearchResult = searcher.FindOne()
            item.SubItems.Add(result.Properties("sAMAccountName")(0).ToString())
            item1.SubItems.Add(result.Properties("title")(0).ToString())
            Dim ADEntry As DirectoryEntry = New DirectoryEntry(result.Path)
            If result.Properties("displayName") Is Nothing Then
                On Error Resume Next
            End If
        Next

Open in new window

0
Comment
Question by:derek7467
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 

Author Comment

by:derek7467
ID: 40409269
Ok, i've gotten this far.  I have a listview that i want to add the ID, samaccountname, and title.  I added the 3 columns to the listview.  I have the below code, but when i run it, it just shows in one long line, and doesnt create the columns.  How can i force it to create the columns and then place each result under each column?

 Dim userIds As IEnumerable(Of String) = {"test1", "test2", "test3"}
        For Each i As String In userids
            Dim de As New DirectoryEntry("LDAP://test.com/DC=test,DC=com")
            Dim LdapFilter As String = "(sAMAccountName=" & i & ")"
            Dim searcher As New DirectorySearcher(de, LdapFilter)
            Dim result As SearchResult = searcher.FindOne()
            ListView1.Items.Add(i)
            ListView1.Items.Add(result.Properties("sAMAccountName")(0).ToString())
            ListView1.Items.Add(result.Properties("title")(0).ToString())
        Next

Open in new window

0
 

Accepted Solution

by:
derek7467 earned 0 total points
ID: 40409328
figured it out with the help from stackexchange:

 Dim userIds As IEnumerable(Of String) = {"test1", "test2", "test3"}
        For Each i As String In userids
            Dim de As New DirectoryEntry("LDAP://test.com/DC=test,DC=com")
            Dim LdapFilter As String = "(sAMAccountName=" & i & ")"
            Dim searcher As New DirectorySearcher(de, LdapFilter)
            Dim result As SearchResult = searcher.FindOne()
            Dim item As ListViewItem = ListView1.Items.Add(i)
            item.SubItems.Add(result.Properties("displayName")(0).ToString())
            item.SubItems.Add(result.Properties("title")(0).ToString())
            item.SubItems.Add(result.Properties("userPrincipalName")(0).ToString())
        Next
0
 

Author Closing Comment

by:derek7467
ID: 40409329
incase anyone ever needs this!
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question