Friday 13 April 2012

Get User profile details on current user in SharePoint

SPWeb web = SPControl.GetContextWeb(Context);
SPUser currentUser = web.CurrentUser;

SPSecurity.RunWithElevatedPrivileges(delegate
{
web.AllowUnsafeUpdates = true;
web.Update();
UserProfileManager upm = new UserProfileManager();
UserProfile uProfile = upm.GetUserProfile(currentUser.LoginName);
Msg.Text = Convert.ToString(uProfile[PropertyConstants.AccountName].Value);
//uProfile[PropertyConstants.Department].Value = "Department";
web.AllowUnsafeUpdates = false;
web.Update();
});

No comments:

Post a Comment