goldenboynh
Programmer
Hi -
I have code that returns exchange information for a particular user from our exchange server. I initially had this running in a vb.net program, and could verify the functionality works correctly (I printed the results to a text file).
I then transitioned the vb file to a class in order to use it from within an asp.net page. I have a function that accesses the exchange server based upon the uid filter. It then sets approximately 20 properties based upon values from the exchange server for a particular user.
The object compiled without error. I then created a very lightweight asp.net page to test the component. However, the component doesn't appear to be working. It's return false, when running in the vb file (see above) it returns true. Any ideas? I have included the code below:
'############### vb.net component #############
Imports System
Imports System.DirectoryServices
Imports System.Collections
Namespace WebUtilities
Public Class EmployeeInfo
Private mstrRDN As String
'... a lot more string declared here...
Private mstrFileId As String
Public Function GetEmployeeInfo(ByVal strUsername As String) As Boolean
Dim objEntry As DirectoryEntry
Dim objSearcher As DirectorySearcher
Dim objSearchResult As SearchResult
Dim objDisplayName As Object
Dim strDisplayName As String
Try
objEntry = New DirectoryEntry("LDAP://exchange-server/ou=CORP,o=mycompany"
' Set up to search for UserMan on the Users node
objSearcher = New DirectorySearcher(objEntry)
objSearcher.Filter = "(&(uid=" & strUsername & ")"
' Find the user
objSearchResult = objSearcher.FindOne()
' Check if the user was found
If Not objSearchResult Is Nothing Then
' Display path for user
Dim myResultPropColl As ResultPropertyCollection
Dim theValue As String
myResultPropColl = objSearchResult.Properties
Dim myKey As String
Dim colHashTable As Hashtable
colHashTable = New Hashtable()
For Each myKey In myResultPropColl.PropertyNames
Dim tab1 As String = " "
Dim myCollection As Object
For Each myCollection In myResultPropColl(myKey)
If myCollection.GetType().ToString() = "System.String" Then
colHashTable(myKey) = myCollection.ToString()
End If
Next myCollection
Next myKey
mstrRDN = colHashTable("rdn"
'... a lot more properties set here...
mstrFileId = colHashTable("extension-attribute-1"
Return True
Else
Return False
End If
Catch
End Try
End Function
Property RDN() As String
Get
Return mstrRDN
End Get
Set(ByVal Value As String)
mstrRDN = Value
End Set
End Property
'... a lot more property declarations here...
Property FileID() As String
Get
Return mstrFileId
End Get
Set(ByVal Value As String)
mstrFileId = Value
End Set
End Property
End Class
End Namespace
'############### asp.net file #############
Imports System.DirectoryServices
Imports WebUtilities.EmployeeInfo
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents lblOut As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myEmployee As WebUtilities.EmployeeInfo
Dim bolRtn As Boolean
myEmployee = New WebUtilities.EmployeeInfo()
bolRtn = myEmployee.GetEmployeeInfo("jdoe"
lblOut.Text = "File ID: " & myEmployee.Department & ", " & bolRtn
End Sub
End Class
I have code that returns exchange information for a particular user from our exchange server. I initially had this running in a vb.net program, and could verify the functionality works correctly (I printed the results to a text file).
I then transitioned the vb file to a class in order to use it from within an asp.net page. I have a function that accesses the exchange server based upon the uid filter. It then sets approximately 20 properties based upon values from the exchange server for a particular user.
The object compiled without error. I then created a very lightweight asp.net page to test the component. However, the component doesn't appear to be working. It's return false, when running in the vb file (see above) it returns true. Any ideas? I have included the code below:
'############### vb.net component #############
Imports System
Imports System.DirectoryServices
Imports System.Collections
Namespace WebUtilities
Public Class EmployeeInfo
Private mstrRDN As String
'... a lot more string declared here...
Private mstrFileId As String
Public Function GetEmployeeInfo(ByVal strUsername As String) As Boolean
Dim objEntry As DirectoryEntry
Dim objSearcher As DirectorySearcher
Dim objSearchResult As SearchResult
Dim objDisplayName As Object
Dim strDisplayName As String
Try
objEntry = New DirectoryEntry("LDAP://exchange-server/ou=CORP,o=mycompany"
' Set up to search for UserMan on the Users node
objSearcher = New DirectorySearcher(objEntry)
objSearcher.Filter = "(&(uid=" & strUsername & ")"
' Find the user
objSearchResult = objSearcher.FindOne()
' Check if the user was found
If Not objSearchResult Is Nothing Then
' Display path for user
Dim myResultPropColl As ResultPropertyCollection
Dim theValue As String
myResultPropColl = objSearchResult.Properties
Dim myKey As String
Dim colHashTable As Hashtable
colHashTable = New Hashtable()
For Each myKey In myResultPropColl.PropertyNames
Dim tab1 As String = " "
Dim myCollection As Object
For Each myCollection In myResultPropColl(myKey)
If myCollection.GetType().ToString() = "System.String" Then
colHashTable(myKey) = myCollection.ToString()
End If
Next myCollection
Next myKey
mstrRDN = colHashTable("rdn"
'... a lot more properties set here...
mstrFileId = colHashTable("extension-attribute-1"
Return True
Else
Return False
End If
Catch
End Try
End Function
Property RDN() As String
Get
Return mstrRDN
End Get
Set(ByVal Value As String)
mstrRDN = Value
End Set
End Property
'... a lot more property declarations here...
Property FileID() As String
Get
Return mstrFileId
End Get
Set(ByVal Value As String)
mstrFileId = Value
End Set
End Property
End Class
End Namespace
'############### asp.net file #############
Imports System.DirectoryServices
Imports WebUtilities.EmployeeInfo
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents lblOut As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim myEmployee As WebUtilities.EmployeeInfo
Dim bolRtn As Boolean
myEmployee = New WebUtilities.EmployeeInfo()
bolRtn = myEmployee.GetEmployeeInfo("jdoe"
lblOut.Text = "File ID: " & myEmployee.Department & ", " & bolRtn
End Sub
End Class