473,503 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Active Directory Query to Listview

30 New Member
Hi All,

Something weried happening when i try and return 4 AD properties to a listview box, here is my code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim li As ListViewItem
  3.  
  4. Dim dirEntry As DirectoryEntry = New DirectoryEntry("LDAP://172.16.0.3/OU=Staff,OU=Users,OU=Accounts,OU=Network,DC=X,DC=local")
  5.  
  6. dirEntry.Username = "x"
  7. dirEntry.Password = "x"
  8.  
  9. Dim search As DirectorySearcher = New DirectorySearcher(dirEntry)
  10. search.Filter = "(&(objectClass=User)(objectCategory=person))"
  11.  
  12. Dim res As SearchResultCollection = search.FindAll()
  13.  
  14. For Each ItemRes As SearchResult In res
  15.  
  16. li = Me.ListView1.Items.Add(ItemRes.Properties("displayname")(0).ToString())
  17. li.SubItems.Add(ItemRes.Properties("department")(0).ToString())
  18. li.SubItems.Add(ItemRes.Properties("homePhone")(0).ToString())
  19. li.SubItems.Add(ItemRes.Properties("mail")(0).ToString())
  20.  
  21. Next
Basically, if i only return the displayname, all the results come back, if i ask for the displayname and the mail as a subitem only 10 items come back, If i ask for department or homePhone to come back only 1 displayname is returned.

If i return the items to messageboxes they return fine.

Have i coded the subitems right on the listview?

Thanks,

James.
Mar 9 '12 #1
1 2707
Asprisa
30 New Member
I managed to fix my own problem, the issue was if the property was empty it caused the rest of the query to go a bit loopy, so get around it i used this:

Expand|Select|Wrap|Line Numbers
  1. li = Me.ListView1.Items.Add(ItemRes.Properties("samaccountname")(0).ToString())
  2.  
  3. If ItemRes.Properties.Contains("department") Then
  4.  
  5. li.SubItems.Add(ItemRes.Properties("department")(0).ToString())
  6.  
  7. Else
  8.  
  9. li.SubItems.Add("Not in database")
  10.  
  11. End If
  12.  
  13. If ItemRes.Properties.Contains("homePhone") Then
  14.  
  15. li.SubItems.Add(ItemRes.Properties("homePhone")(0).ToString())
  16.  
  17. Else
  18.  
  19. li.SubItems.Add("Not in database")
  20.  
  21. End If
  22.  
  23. If ItemRes.Properties.Contains("mail") Then
  24.  
  25. li.SubItems.Add(ItemRes.Properties("mail")(0).ToString())
  26.  
  27. Else
  28.  
  29. li.SubItems.Add("Not in database")
  30.  
  31. End If
  32.  
Mar 9 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3656
by: Ran Davidovitz | last post by:
Hi. We need to create a view of our active directory users (we have 2500). I found out that there is max page size of 1000, so we cannot get more data. Anyone found a solution to that...
0
1022
by: JasonM | last post by:
Help! I'm new to C# and am having trouble with the following code: ..... DirectoryEntry root = new DirectoryEntry("LDAP://<DOMAIN>"); DirectorySearcher searcher = new DirectorySearcher(root);...
3
2061
by: mpriem | last post by:
Hi, I am trying to enumerate Exchange Admin groups, but fail to with the folowing code. Can someone help me with this issue. The executing user has sufficient permissions. using System; ...
1
1254
by: Arvind P Rangan | last post by:
Hi, How do u interpret a Active Directory Structure into code format. Like i have a ADS Structrue like this main.domain.com + AB + UB + AC All my information are in AC
1
4732
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
1
1764
by: Tash | last post by:
I am having a weird problem. I am trying to use the following code to query active directory. Function IsExistInAD(ByVal loginName As String) As Boolean Dim userName As String =...
0
5396
by: Chung Leong | last post by:
In this brief tutorial I'll describe how you retrieve information from an Active Directory through the OLE-DB extension. While it is possible to use the LDAP extension to achieve the same goal, as...
0
2001
by: dug04 | last post by:
Hi I am trying to write a query that will select all users in the Organization bucket in active directory. The problem is that within the Organization bucket, there are many other buckets. I...
7
16449
by: kooch54 | last post by:
I am trying to write a script to simply query the group members in an active directory group. I need to use LDAP to make sure I capture any global global group nestings that may occur. I already...
3
3001
by: =?Utf-8?B?YXppZWdsZXI=?= | last post by:
Hello, everybody. I'd like to do this: For a big program (a web service) I need information about the usergroups an active-directory-user is member of. To be more precise, I need to know if a...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5596
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
747
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.