1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Programmatically accessing custom profile fields.

Programmatically accessing custom profile fields.

6 posts, 0 answered
  1. Richard
    Richard avatar
    15 posts
    Registered:
    17 Aug 2012
    03 Aug 2012
    Link to this post
    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
  2. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    04 Aug 2012
    Link to this post
    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.





  3. Richard
    Richard avatar
    15 posts
    Registered:
    17 Aug 2012
    04 Aug 2012
    Link to this post
    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?
  4. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    04 Aug 2012
    Link to this post
    Don't know about FacebookProfile.
    The code refers to Sitefinity user profile, enabling you to read custom properties.
  5. Richard
    Richard avatar
    15 posts
    Registered:
    17 Aug 2012
    05 Aug 2012
    Link to this post
    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
  6. Chanan Zass
    Chanan Zass avatar
    123 posts
    Registered:
    21 Aug 2012
    05 Aug 2012
    Link to this post
    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.
6 posts, 0 answered