How the "department name" and "manager" attribute value could be retrieved from active directory programmatically? For ex. i will have custom newform.aspx to create some new item, in the code-behind of the custom newform.aspx i have to send email to the manager of the current user, and log the department name. So sharepoint designer activities is not suitable for my case.
The below code access current user's department and manager from AD:
The other way to do this is to use DirectoryEntry and DirectorSearcher class:
Converting string to SPUser
Note: myWeb is the object of SPWeb class
Hope this helps.