Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear brothers & Friends,
I am not very much expert in writing fields in active directory I really need your help please.
I am able to retrieve user information from Active Directory as per below code. but how can I authorized current to edit and update there telephone numbers. this application is running in sharepoint server.

Dim netBIOSname As String = Me.Page.User.Identity.Name
      Dim sAMAccountName As String = netBIOSname.Substring(netBIOSname.LastIndexOf("\"c) + 1)
      txtuser.Text = sAMAccountName
      Try
          Dim userName As String = txtuser.Text
          Dim searcher As New DirectoryServices.DirectorySearcher( _
             "(mailNickname=" + userName + ")")
          Dim result As DirectoryServices.SearchResult = searcher.FindOne()
          If result Is Nothing Then
              Label2.Text = "Unable to find user: " + userName
          Else
              Dim employee As DirectoryServices.DirectoryEntry = result.GetDirectoryEntry()
              txtfirstname.Text = employee.Properties("givenName").Value.ToString()
              txtlastname.Text = employee.Properties("sn").Value.ToString()
              txtfullname.Text = employee.Properties("cn").Value.ToString()
              txtempid.Text = employee.Properties("physicalDeliveryOfficeName").Value.ToString()
              txttitle.Text = employee.Properties("title").Value.ToString()
              txttele.Text = employee.Properties("telephoneNumber").Value.ToString()
              txtdept.Text = employee.Properties("department").Value.ToString()
              txtmobile.Text = employee.Properties("mobile").Value.ToString()
              Dim ManagerName As String = employee.Properties("manager").Value.ToString()
              ManagerName = ManagerName.Substring(3, ManagerName.IndexOf(",") - 3)
              Dim searchMgr As New DirectoryServices.DirectorySearcher("(cn=" + ManagerName + ")")
              Dim resultMgr As DirectoryServices.SearchResult = searchMgr.FindOne()

              If resultMgr Is Nothing Then
                  Label2.Text = "Unable to find Manager: " + ManagerName
              Else
                  Dim empManager As DirectoryServices.DirectoryEntry = resultMgr.GetDirectoryEntry()
                  searchMgr.Dispose()
                  resultMgr = Nothing
                  empManager.Close()
              End If
              searcher.Dispose()
              result = Nothing
              employee.Close()
          End If


      Catch ex As Exception
          Label2.Text = "The following error occurred: " + ex.Message.ToString()
      End Try


What I have tried:

retrieve user information from Active Directory 
Posted
Updated 31-Jan-18 1:13am

1 solution

very good blog on AD updation
you will get everything here

Working with Active Directory in VB.NET[^]
 
Share this answer
 
v2
Comments
Dave Kreskowiak 31-Jan-18 7:46am    
Only a year too late. I doubt the OP is still looking for an answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900