Programmatically accessing custom profile fields.
Hello,
I am having some trouble accessing fields that are contained in User Profiles that have been created in the back-end interface. The profile I want to access is called Facebook Profile (with a developer name of 'facebookprofile').
The documentation accessing custom profile data like this is lacking, and I have had to search the forums for some answers. The best thing I found was this:
And
for
custom profiles;
UserProfile owsProfile = userProfileManager.GetUserProfile(user.Id,
"Telerik.Sitefinity.Security.Model.owscustomerprofile"
);
var w = Telerik.Sitefinity.Model.DataExtensions.GetValue(owsProfile,
"School"
);
Regards,
Peter
This is the way we get profile properties (there are probably more elegant ways, but this works):
using Telerik.Sitefinity.Security;
using Telerik.Sitefinity.Security.Model;
using Telerik.Sitefinity.Security.Claims;
using Telerik.Sitefinity.Model;
var identity = ClaimsManager.GetCurrentIdentity();
var userName = identity.Name;
var userId = identity.UserId;
UserProfileManager profileManager = UserProfileManager.GetManager();
var prof = profileManager.GetUserProfiles(userId).Where(p => p.GetType().FullName == typeof(SitefinityProfile).FullName).SingleOrDefault();
prof.GetValue("[ProfileProperty")
Hi,
Don't know about FacebookProfile.
The code refers to Sitefinity user profile, enabling you to read custom properties.
Hi,
I am a little bit confused about what exactly a profile is. Is the SitefinityProfile type something to do with the provider of the profiles (and holds the data for the Basic Profile and my custom created Facebook Profile)? Or, is it the same as Basic Profile (with my Facebook Profile a separate type)?
Profile properties are data items associated with a registered user (like the user's first name, last name, etc.). It is not a Sitefinity concept, but Sitefinity manages profile properties in its own way. As a developer you can add as many custom properties as you wish (like user's department, coroproate position, etc.).
To learn more, google .NET User Profile.