Hi,
I currently have a function that can retrieve information from the Active Directory Store, this works fine on my system.
However what i ask is for someone to assist me in changing the GetUserInfo() function to a WriteUserInfo() function.
In reality what i mean is can someone have a look and advise what changes need to be made to write to the AD instead of read from the AD.
I have posted a copy of my current code below
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Web" %>
<%@ import Namespace="System.Security.Principal" %>
<%@ import Namespace="System.Configuration" %>
<%@ import Namespace="System.DirectoryServices" %>
<script runat=server>
Public Function GetUserInfo(ByVal inSAM As String, ByVal inType As String) As String
Try
Dim sPath As String = "LDAP://-<ADCONTROLLER>-"
Dim SamAccount As String = Right(inSAM, Len(inSAM) - InStr(inSAM, "\"))
Dim myDirectory As New DirectoryEntry(sPath)
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()
'I expect only one user from search result
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 Properites, they contain the usefull info
myResultPropColl = mySearchResult.Properties
'displayname, mail
'Retrieve from the properties collection the display name and email of the user
myResultPropValueColl = myResultPropColl.Item(inType)
Return CStr(myResultPropValueColl.Item(0))
Catch ex As System.Exception
'do some error return here.
End Try
End Function
Sub Page_Load(ByVal Sender as System.Object, ByVal E as System.EventArgs)
'For Listing of AD Fields check out
'http://www.computerperformance.co.uk/Logon/LDAP_attributes_active_directory.htm
Dim UserAccount As String
UserAccount = "<<USERNAME>>"
Dim sEmail As String = GetUserInfo(UserAccount, "mail")
Dim sFirstName As String = GetUserInfo(UserAccount, "givenName")
Dim sLastName As String = GetUserInfo(UserAccount, "sn")
Dim sCity As String = GetUserInfo(UserAccount, "l")
Dim sState As String = GetUserInfo(UserAccount, "st")
Dim sStreetAddress As String = GetUserInfo(UserAccount, "streetAddress")
Dim sPostalCode As String = GetUserInfo(UserAccount, "postalCode")
Dim sPhone As String = GetUserInfo(UserAccount, "HomeNumber")
Dim sCountry As String = GetUserInfo(UserAccount, "co")
lblMessage.Text = sFirstName & "<br>" _
& sLastName & "<br>" _
& sEmail & "<br>" _
& sPhone
End Sub
</script>
<p>
<font face="Arial">
<asp:Label id="lblMessage" Text="No Info!"
runat="server" font-size="12pt"
font-name="Arial" font-bold="True">
</asp:Label>
</font>
</p>
Thank you to anyone who may be able to help
Andrew Vint