Docly

How to update an user ?

Estimated reading: 1 minute 39 views

How to update the basic information of the user ?

Update user details (like Firstname,Lastname, email, Description etc)

// Get the membership user
var user = runtime.Membership.GetUser("jsmith");

//Edit user
//you can update the details of the user
user.FirstName = "Johny";
user.Title = "Mr";
user.Comment = "User from IT Team";
user.Email = "modified@xyz.com";

//Lock/Unlock user
user.IsLockedOut = true;

//Approve/Unapprove user
user.IsApproved = false;

//update user details
runtime.Membership.UpdateUser(user);

How to update an user profile ?

Get the value of the profile

// Get the user
var user = runtime.Membership.GetUser("jsmith"); 

// Get the value of the attributes
string companyName = user.GetValue<string>("CompanyName"); 
int age = user.GetValue<int>("Age"); 
DateTime dtBirthDate = user.GetValue<DateTime>("BirthDate");

Update the profile values of the user

// Get the user
var user = runtime.Membership.GetUser("jsmith");

// Set a values
user.SetValue<string>("CompanyName", "Novalys");
user.SetValue<int>("Age", 35);
user.SetValue<DateTime>("BirthDate", DateTime.Now.Date);

// Update the user
runtime.Membership.UpdateUser(user);

Leave a Comment

Share this Doc
CONTENTS