Wednesday, 19 November 2014

Get the User Profile in Auto Push Back event on people picker in SharePoint site programmatic.


The following description describes, programmatic how to get the user profile details automatically when the user is resolved in people picker field.

==> If you want to get user profile and show  automatically when resolve the user by people picker, do following steps:

Step 1:

Add the "AutoPushBack='true' " attribute to people picker control in SamplePage.aspx page.

Step 2:

Add the following code in your code behind (SamplePage.aspx.cs) file in the Page Load Event.


==> If you want to get the user profile after an any other event like click on some button, then directly place the following code in click event.


// Code snippent

==> using Microsoft.Office.Service.Userprofie  // add this reference first

==> In the following code snippet "spnLoginName" is the id of a label to display result and "peUser" is the people picker control Id, so replace it with what yours controls id's


try
   {
      using (SPSite site = new SPSite(SPContext.Current.Web.Url))
        {
          ServerContext context = ServerContext.GetContext(site);

          UserProfileManager   profileManager = new   UserProfileManager(context);

          PickerEntity   entity = (PickerEntity)peUser.ResolvedEntities[0];

          UserProfile   profile = profileManager.GetUserProfile(entity.Key);

          spnLoginName.InnerText = profile[PropertyConstants.SAMUserName].Value.ToString();
                 
         }
             
    }
 catch
     {
         throw;
      }


== > Through this code you get all the user profiles who are exited in you SharePoint Site.

No comments:

Post a Comment