Showing posts with label Update. Show all posts
Showing posts with label Update. Show all posts

Friday, 13 April 2012

Update email address at SQL server Database in FBA (SharePoint C#)

try
{
MembershipUser usr = System.Web.Security.Membership.Providers["FBAUser"].GetUser(SPContext.Current.Web.CurrentUser.LoginName, true);
usr.Email = "emailaddress@email.com";
System.Web.Security.Membership.UpdateUser(usr);
Msg.Text += "Email is Changed at FBA <br/>";
}
catch (Exception ex)
{
Msg.Text += " *Email is not updated at FBA <br/>" + ex.Message;
}

Update the user information list in SharePoint at User Profile C#

SPSite spsite = SPContext.Current.Site;
SPWeb spweb = spsite.OpenWeb();
SPList splist = spweb.SiteUserInfoList;
SPListItem userInfo = splist.Items.GetItemById(SPContext.Current.Web.CurrentUser.ID);
try{
Msg.Text = " ";
if ((txtFirstName.Text != "") || (txtLastName.Text != ""))
{
userInfo["Title"] = txtFirstName.Text + " " + txtLastName.Text;
}
if (txtEmail.Text != "")
{
userInfo["Work e-mail"] = txtEmail.Text;
}
if (txtFirstName.Text != "")
{
userInfo["First name"] = txtFirstName.Text;
}
if (txtLastName.Text != "")
{
userInfo["Last name"] = txtLastName.Text;
}
if (txtMobilePhone.Text != "")
{
userInfo["Mobile phone"] = txtMobilePhone.Text;
}
if (txtWorkPhone.Text != "")
{
userInfo["Work phone"] = txtWorkPhone.Text;
}
if (txtUsername.Text != "")
{
userInfo["User name"] = txtUsername.Text;
}
Msg.Text += "Profile Details are updated";
userInfo.Update();
}
catch{
Msg.Text = "Profile Details are not updated";
}

Update the user profile picture in SharePoint

SPServiceContext context = SPServiceContext.GetContext(SPContext.Current.Site);
UserProfileManager profileManager = new UserProfileManager(context);
UserProfile theProfile = profileManager.GetUserProfile(SPContext.Current.Web.CurrentUser.LoginName);
theProfile["PictureUrl"].Value = "<img url>";
theProfile.Commit();