Getting SharePoint User's Profiles
SPSecurity.RunWithElevatedPrivileges(delegate()
{
try
{
using (SPSite oSite = new SPSite(SPContext.Current.Site.ID, SPContext.Current.Site.SystemAccount.UserToken))
{
SPServiceContext context = SPServiceContext.GetContext(oSite);
UserProfileManager myProfileManager = new UserProfileManager(context);
string CurrentUser = SPContext.Current.Web.CurrentUser.LoginName;
UserProfile myProfile = myProfileManager.GetUserProfile(CurrentUser);
dt.Rows.Add(Convert.ToString(myProfile["FirstName"].Value), Convert.ToString(myProfile["Department"].Value));
//dt.Rows.Add(Convert.ToString(myProfile["LastName"].Value), Convert.ToString(myProfile["FirstName"].Value), Convert.ToString(myProfile["Department"].Value), Convert.ToString(myProfile["WorkEmail"].Value), Convert.ToString(myProfile["WorkPhone"].Value), Convert.ToString(myProfile["CellPhone"].Value));
}
CurentUserGrd.DataSource = dt;
CurentUserGrd.DataBind();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
});
Comments
Post a Comment