Programmatically accessing custom profile fields.

Posted by Community Admin on 04-Aug-2018 00:27

Programmatically accessing custom profile fields.

All Replies

Posted by Community Admin on 03-Aug-2012 00:00

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

Unfortunately, this does not appear to work (the GetUserProfile method returns a null value for the user profile).

Can anybody suggest a way that I can access and edit the data contained in custom user profiles?

Thanks,
Richard

Posted by Community Admin on 04-Aug-2012 00:00

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;

Then:
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();

You get the properties by calling:
prof.GetValue("[ProfileProperty")

Hope that helps.





Posted by Community Admin on 04-Aug-2012 00:00

Hi,

Thanks for the reply. For some reason, that gives a 'null' user profile. Might it be that I am using a custom user profile type (FacebookProfile, rather than BasicProfile) to store the data?

Posted by Community Admin on 04-Aug-2012 00:00

Don't know about FacebookProfile.
The code refers to Sitefinity user profile, enabling you to read custom properties.

Posted by Community Admin on 05-Aug-2012 00:00

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)?

Hope my question makes sense!

Thanks,
Richard

Posted by Community Admin on 05-Aug-2012 00:00

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.

This thread is closed