Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ActiveDS vs. DirectoryServices weird error

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
US
I have a project that used the ActiveDS COM object. I am now rewriting it using the DirectoryServerices namespace within .Net
Code:
Dim ADGrp As IADsGroup
Dim ADUsr As IADsUser
Dim DirEntry As New DirectoryEntry("LDAP://...")
Dim DirSearch As New DirectorySearcher(DirEntry)
Dim UserSearch As New DirectorySearcher(DirEntry)
Dim Result, UResult As SearchResult
Dim X As Integer
Dim Emails As New ArrayList()
My ActiveDS code
Code:
ADGrp = GetObject("LDAP://...")
For Each ADUsr In ADGrp.Members
  If ADUsr.AccountDisabled = False Then
    Emails.Add(ADUsr.FullName)
  End If
Next
worked fine. I inserted the full name of the user into an arraylist (emails).

with DirectoryServices
Code:
DirSearch.Filter = ("(CN=All Staff)")
DirSearch.PropertiesToLoad.Add("member")
Result = DirSearch.FindOne
For X = 0 To Result.Properties("member").Count - 1
  UserSearch.Filter = ("(" & Left(Result.Properties("member").Item(X), InStr(Result.Properties("member").Item(X), ",") - 1) & ")")
  UserSearch.PropertiesToLoad.Add("DisplayName")
  UResult = UserSearch.FindOne()
  Emails.Add(UResult.Properties("DisplayName").Item(0))
Next X
I get a null instance error when adding the names to the arraylist.

if I put the
Code:
emails.add(...)
in a try/catch statement the arraylist is populated, but the name for the null instance is displayed as
Code:
AFFREL01$
in the array list.

Anybody know why it's inserting this value if it was a null instance? Why is it being added if the try/catch statement looks like this:
Code:
Try
  Emails.Add(Emails.Add(UResult.Properties("DisplayName").Item(0))
Catch
End Try
Shouldn't it do nothing?

Jason Meckley
Database Analyst
WITF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top