locked
problem getting properties value after connecting to a Novell Server RRS feed

  • Question

  • User750184344 posted

    Hi,

    I am accessing all LDAP users by using this code.

    When I connect to Novell, It shows me "objResultsCollection.Count" as 42 but when I try to access the property value, it throws error "An invalid dn syntax has been specified."

    So I am totally confused that I am getting no. of users but not able to get its values, Can you please tell me what's wrong in this code ? I want to access its “sn”, “name”, “mail” etc. properties values.

    ################################################################################################################

     

    Dim MyServerName As String = "LDAP://IPAddress:389/o=nsc"

            Dim Y As ArrayList

            Dim ResultFields() As String = {"securityEquals", "cn", "sn", "uid", "givenname"}

            Dim ReturnRetults() As String = {"name"}

            Y = GetLDAPUsers(MyServerName, ResultFields, , , , ReturnRetults)

     

     

     

    Public Function GetLDAPUsers( _

            ByVal LDAPServerConnectString As String, _

            Optional ByVal SearchRangeFields() As String = Nothing, _

            Optional ByVal UserName As String = Nothing, _

            Optional ByVal Password As String = Nothing, _

            Optional ByVal AuthenticationType As AuthenticationTypes = Nothing, _

            Optional ByVal ReturnProperties() As String = Nothing, _

            Optional ByVal SearchString As String = "", _

            Optional ByRef ErrorOccured As Boolean = False, _

            Optional ByRef ErrorMessage As String = "") _

            As ArrayList

     

     

            GetLDAPUsers = New ArrayList

            ErrorOccured = False

            ErrorMessage = ""

     

            Dim objEntry As DirectoryEntry

            Dim objResultsCollection As SearchResultCollection

            Dim objResult As SearchResult

            Dim RetArray As New ArrayList

            Dim Countof As Integer

            Dim i As Integer

            Dim BuildString As New StringBuilder

            Dim AppendString As Boolean = False

     

            Dim objSearcher As DirectorySearcher

     

            Try

                objEntry = New DirectoryEntry(LDAPServerConnectString)            If UserName IsNot Nothing AndAlso UserName.Length > 0 Then

                   

                    objEntry.Username = UserName

                End If

                If Password IsNot Nothing AndAlso Password.Length > 0 Then

                    objEntry.Password = Password

                End If

                If AuthenticationType.ToString.Length > 0 Then

                    objEntry.AuthenticationType = AuthenticationType

                End If

              

                objSearcher = New DirectorySearcher(objEntry)

                With objSearcher

                    If SearchRangeFields IsNot Nothing AndAlso SearchRangeFields.Length > 0 Then

                        .PropertiesToLoad.AddRange(SearchRangeFields)

                    End If

                    .PropertyNamesOnly = True

                    '.PropertiesToLoad.Add("name")

     

                    'TODO: hardcoded filter method needs to be changed

                    If SearchString IsNot Nothing Then

                        If SearchString.Length > 0 Then

                            .Filter = "(&(cn=" & SearchString & "*))"

                        End If

                    End If

     

                    objResultsCollection = .FindAll()

                End With

     

                Countof = objResultsCollection.Count

                If Countof > 0 Then

     

                    For Each objResult In objResultsCollection

                        AppendString = False

                        BuildString = New StringBuilder

                        For i = LBound(ReturnProperties) To UBound(ReturnProperties)

                            If objResult.Properties.Contains(ReturnProperties(i)) = True Then

                                If objResult.GetDirectoryEntry.Properties.Contains(ReturnProperties(i)) = True Then

                                    If objResult.GetDirectoryEntry.Properties(ReturnProperties(i)).Value IsNot Nothing Then

                                        AppendString = True

                                        If BuildString.Length > 0 Then

                                            BuildString.Append(vbCrLf)

                                        End If

                                        BuildString.Append(ReturnProperties(i))

                                        BuildString.Append("=")

                                        BuildString.Append(objResult.GetDirectoryEntry.Properties(ReturnProperties(i)).Value)

                                    End If

                                End If

                            End If

     

                        Next

                        If AppendString = True Then

                            RetArray.Add(BuildString.ToString)

                        End If

     

                    Next

                End If

            Catch ex As Exception

                MsgBox("Error is " & ex.Message)

                Return RetArray

            End Try

     

            Return RetArray

     

        End Function

    ################################################################################################################

    Thanks,

    Nirav

    Tuesday, September 12, 2006 10:13 AM

All replies

  • User1354132231 posted

    Well... you left off the important part: what does 'ReturnProperties()' do?  Also, what attribute and syntax are you expecting when it blows up?  Finally, I just wanted to warn you that your performance with this is going to suck (big time).  You are misusing the GetDirectoryEntry method.

     

    Wednesday, September 13, 2006 9:06 AM