Access User Profile Custom Fields
I am looking for a way to access custom fields in a user profile. I have created a new User Profile Type called Customer and now have added a custom number field called OfficeID. I would like to be able to get the user and the values of the custom fields. The following is the code I have tried based on previous posts, but office returns 0 when the value should be 1. Any suggestions?
Hello Michael,
To get the field value you could use the following method:
public
string
GetUserProfileFieldByUserId(Guid userId, UserManager userManager)
var myType =
"Telerik.Sitefinity.Security.Model.customer"
;
if
(UserProfilesHelper.ProfileTypeExists(myType))
var profileManager = UserProfilesHelper.GetUserProfileManager<SitefinityProfile>();
var profile = profileManager.GetUserProfile(userId, myType);
var fieldValue = profile.GetValue(
"OfficeID"
).ToString();
return
fieldValue;
return
null
;
UserManager userManager = UserManager.GetManager();
var userId = userManager.GetUsers().Where(uid => uid.UserName ==
"Username"
).FirstOrDefault().Id;
var value = GetUserProfileFieldByUserId(userId, userManager);
using
Telerik.Sitefinity.Model;
var myType = "Telerik.Sitefinity.Security.Model.customer";