I am getting a compilation error with the following code :
<script runat="server">
Public Class ActiveDirectory
Public Function GetUserInfo(ByVal inSAM as String, ByVal inType as String) as String
Try
Dim sPath as String = "LDAP://myDomain.com/DC=mydomain,DC=com"
Dim SamAccount as String = Right(inSam, Len(inSam) - InStr(inSam, "\"))
Dim myDirectory as = New DirectoryEntry(sPath, "EnterPrise Admin", "Password")
Dim mySearcher as New DirectorySearcher(myDirectory)
Dim mySearchResultColl as SearchResultCollection
Dim mySearchResult as SearchResult
Dim myResultPropColl as ResultPropertyCollection
Dim myResultPropValueColl as ResultPropertyValueCollection
'Build LDAP query
mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" & SamAccount &"))")
mySearchResultColl = mySearcher.Findall()
'We only expect one user from the search
Select Case mySearchResultColl.Count
Case 0
Return "Null"
Exit Function
Case is > 1
Return "Null"
Exit Function
end select
' Get the search result from the collection
mySearchResult = mySearchResultColl.Item(0)
' Get the properties, they contain the usefull info
myResultPropColl = mySearchResult.Properties
' Return the requested property.. displayname, mail, etc
myResultPropValueColl = myResultPropColl.Item(inType)
Return CStr(myResultPropValueColl.Item(0))
Catch ex as System.Exception
' Handle errors
End try
end function
Dim sEmail as String = GetUserInfo(User.Identity.Name, "mail")
end class
The Error is Type Expected and its on the following line of code :
Dim myDirectory as = New DirectoryEntry(sPath, "EnterPrise Admin", "Password")
I found out that the problem was actually to do with me not being able to import System.DirectoryServices I had to copy the .dll file to a bin folder in my applications folder
strohj
Member
175 Points
35 Posts
DirectoryEntry error.... "Type expected."
Nov 03, 2003 07:59 PM|LINK
<script runat="server"> Public Class ActiveDirectory Public Function GetUserInfo(ByVal inSAM as String, ByVal inType as String) as String Try Dim sPath as String = "LDAP://myDomain.com/DC=mydomain,DC=com" Dim SamAccount as String = Right(inSam, Len(inSam) - InStr(inSam, "\")) Dim myDirectory as = New DirectoryEntry(sPath, "EnterPrise Admin", "Password") Dim mySearcher as New DirectorySearcher(myDirectory) Dim mySearchResultColl as SearchResultCollection Dim mySearchResult as SearchResult Dim myResultPropColl as ResultPropertyCollection Dim myResultPropValueColl as ResultPropertyValueCollection 'Build LDAP query mySearcher.Filter = ("(&(objectClass=user)(samaccountname=" & SamAccount &"))") mySearchResultColl = mySearcher.Findall() 'We only expect one user from the search Select Case mySearchResultColl.Count Case 0 Return "Null" Exit Function Case is > 1 Return "Null" Exit Function end select ' Get the search result from the collection mySearchResult = mySearchResultColl.Item(0) ' Get the properties, they contain the usefull info myResultPropColl = mySearchResult.Properties ' Return the requested property.. displayname, mail, etc myResultPropValueColl = myResultPropColl.Item(inType) Return CStr(myResultPropValueColl.Item(0)) Catch ex as System.Exception ' Handle errors End try end function Dim sEmail as String = GetUserInfo(User.Identity.Name, "mail") end classThe Error is Type Expected and its on the following line of code : Any ideas ?dunnry
Star
9098 Points
1806 Posts
Re: DirectoryEntry error.... "Type expected."
Nov 03, 2003 10:31 PM|LINK
Weblog
The Book
LDAP Programming Help
strohj
Member
175 Points
35 Posts
Re: DirectoryEntry error.... "Type expected."
Nov 04, 2003 04:15 PM|LINK
dunnry
Star
9098 Points
1806 Posts
Re: DirectoryEntry error.... "Type expected."
Nov 04, 2003 05:14 PM|LINK
Weblog
The Book
LDAP Programming Help