Getting User Profile
private void GetUserProfile()
{
try
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPServiceContext oSPServiceContext = SPServiceContext.GetContext(site);
UserProfileManager upm = new UserProfileManager(oSPServiceContext);
SPUser spUser = null;
if (Request.Params["ID"] != null)
{
spUser = web.EnsureUser("DC\\" + lblKaizenOwnerValue.Text);
}
else
{
spUser = web.CurrentUser;
}
// UserProfileManager ObjProfMgr = new UserProfileManager(oSPServiceContext);
UserProfile profile = upm.GetUserProfile(spUser.LoginName);//web.CurrentUser.LoginName);
{
if (profile[PropertyConstants.CellPhone].Value != null)
txtContactNoValue.Text = profile[PropertyConstants.CellPhone].ToString();
//if (profile[PropertyConstants.Department].Value != null)
// lblDepartmentValue.Text = profile[PropertyConstants.Department].ToString();
//if (profile[PropertyConstants.HireDate].Value != null)
// lblDateValue.Text = profile[PropertyConstants.HireDate].ToString();
}
}
}
}
catch (Exception ex)
{
Page.ClientScript.RegisterClientScriptBlock(typeof(SPAlert), "alert", "<script language=\"javascript\">alert('" + ex.Message + "')</script>");
}
}
Comments