I created a sharepoint picker and when user enter an ID and click on submit, then the following code should get me their firstname and lastname from active directory. Right now it is working for only my username. Can someone please help me out with this.
PickerEntity pickEntity = (PickerEntity)peoplePicker.ResolvedEntities[0];
string username = pickEntity.Key;
SPSite siteCollection = new SPSite(SPContext.Current.Web.Url.ToString());
SPServiceContext serverContext = SPServiceContext.GetContext(siteCollection);
UserProfileManager profileManager = new UserProfileManager(serverContext);
UserProfile profile = profileManager.GetUserProfile(username);
string FirstName = profile["FirstName"].Value.ToString();
string LastName = profile["LastName"].Value.ToString();