locked
how to get the active directory data like Name,email and contact number and display name into textboxes in server objcect model in sp2010? RRS feed

  • Question

  • how to get the active directory data like Name,email and contact number and display name into textboxes  in server objcect model in sp2010?

    getting some fields from active directory and save the data into custom list.how is it possible?

    please help in above code?

    Tuesday, May 22, 2012 1:14 PM

Answers

  • Hello Sudhir,

    There are classes and methods in Microsoft.net framework to access the active directory

    Please take look at following link

    http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C - gives the probably entire server object model of AD.

    http://www.codeproject.com/Articles/9570/Querying-Microsoft-Active-Directory-Using-Microsof

    Add items in Sharepoint list

    http://www.mindfiresolutions.com/Add-Update-and-Delete-List-Items-Programmatically-in-Sharepoint-372.php

    Please let me know if you have any concern on this.

    Thanks

    Saumil


    • Edited by Saumil Thakkar Tuesday, May 22, 2012 1:38 PM adding more info
    • Marked as answer by Qiao Wei Friday, June 1, 2012 9:29 AM
    Tuesday, May 22, 2012 1:36 PM
  • Hi Sudhir,

    Hopefully below lines may be of some help. I have used below code snippet to read user values from User Profile and written to various form fields. When I save this form these fields get written to the server.

    using (SPSite site = new SPSite("http://intranet"))

                {
                    SPList l = SPContext.Current.List;
                    SPListItem li = SPContext.Current.ListItem;
                    if (li["PersonName"] == null)
                    {

                        SPServiceContext _context = SPServiceContext.GetContext(site);
                        UserProfileManager _profileManager = new UserProfileManager(_context);

                        string username = SPContext.Current.Web.CurrentUser.LoginName;
                        UserProfile _profile = _profileManager.GetUserProfile(username);
                        SPWeb web = SPContext.Current.Web;
                        web.AllowUnsafeUpdates = true;

                        PersonPhone.Text = _profile[PropertyConstants.WorkPhone].ToString();
                        PersonEmail.Text = _profile[PropertyConstants.WorkEmail].ToString();
                        PersonFullName.Text = _profile[PropertyConstants.FirstName] + " " + _profile[PropertyConstants.LastName];
                        PersonOrganisation.Text = _profile[PropertyConstants.Office].ToString(); 
                       PersonPosition.Text= _profile[PropertyConstants.JobTitle].ToString();
                    }

    You can save this form using command    SaveButton.SaveItem(SPContext.Current, false, ""); on button click event.

    Please do not hesistate to contact if further information is required.

    Regards

    P

                   
    • Marked as answer by Qiao Wei Friday, June 1, 2012 9:29 AM
    Tuesday, May 22, 2012 3:07 PM

All replies

  • Hello Sudhir,

    There are classes and methods in Microsoft.net framework to access the active directory

    Please take look at following link

    http://www.codeproject.com/Articles/18102/Howto-Almost-Everything-In-Active-Directory-via-C - gives the probably entire server object model of AD.

    http://www.codeproject.com/Articles/9570/Querying-Microsoft-Active-Directory-Using-Microsof

    Add items in Sharepoint list

    http://www.mindfiresolutions.com/Add-Update-and-Delete-List-Items-Programmatically-in-Sharepoint-372.php

    Please let me know if you have any concern on this.

    Thanks

    Saumil


    • Edited by Saumil Thakkar Tuesday, May 22, 2012 1:38 PM adding more info
    • Marked as answer by Qiao Wei Friday, June 1, 2012 9:29 AM
    Tuesday, May 22, 2012 1:36 PM
  • Hi Sudhir,

    Hopefully below lines may be of some help. I have used below code snippet to read user values from User Profile and written to various form fields. When I save this form these fields get written to the server.

    using (SPSite site = new SPSite("http://intranet"))

                {
                    SPList l = SPContext.Current.List;
                    SPListItem li = SPContext.Current.ListItem;
                    if (li["PersonName"] == null)
                    {

                        SPServiceContext _context = SPServiceContext.GetContext(site);
                        UserProfileManager _profileManager = new UserProfileManager(_context);

                        string username = SPContext.Current.Web.CurrentUser.LoginName;
                        UserProfile _profile = _profileManager.GetUserProfile(username);
                        SPWeb web = SPContext.Current.Web;
                        web.AllowUnsafeUpdates = true;

                        PersonPhone.Text = _profile[PropertyConstants.WorkPhone].ToString();
                        PersonEmail.Text = _profile[PropertyConstants.WorkEmail].ToString();
                        PersonFullName.Text = _profile[PropertyConstants.FirstName] + " " + _profile[PropertyConstants.LastName];
                        PersonOrganisation.Text = _profile[PropertyConstants.Office].ToString(); 
                       PersonPosition.Text= _profile[PropertyConstants.JobTitle].ToString();
                    }

    You can save this form using command    SaveButton.SaveItem(SPContext.Current, false, ""); on button click event.

    Please do not hesistate to contact if further information is required.

    Regards

    P

                   
    • Marked as answer by Qiao Wei Friday, June 1, 2012 9:29 AM
    Tuesday, May 22, 2012 3:07 PM