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

Forums / General Discussions / retrieving custom profile fields

retrieving custom profile fields

10 posts, 1 answered
  1. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    19 Apr 2011
    Link to this post
    Hi all,
    First, I am not a programmer and am learning as I go, so I apologize if this is a very simple matter. I was wondering if someone could point me in the right direction.

    I know I can programmaticly pull for instances the current user's name using:
    var UserID = Telerik.Sitefinity.Security.SecurityManager.GetCurrentUserName();
    lblInfo.Text = UserID;

    Using the new custom field ability with 4.1, I added a field in my profile called "memberID" which is an assigned number for our members. How can I retrieve that similar to the example above to display it to a logged in user?

    Thank you in advance for any insight or suggestions.
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    19 Apr 2011
    Link to this post
    Hello Amanda,

    Here is a sample code that gets the value of a custom field

               UserManager manager = UserManager.GetManager();
               User user = manager.GetUser("test");

               var pm1 = UserProfileManager.GetManager();
               var p1 = pm1.GetUserProfile(user.Id, typeof(SitefinityProfile).FullName);
               var value1 = p1.GetValue("CustomFieldName");

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Answered
  3. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    19 Apr 2011
    Link to this post
    Thank you very much Ivan!  Could you tell me the namespace I need to reference for UserManager?

    Thanks again
  4. j8
    j8 avatar
    20 posts
    Registered:
    30 Oct 2007
    21 Apr 2011
    Link to this post

    Hi,

    This doesn't work for me. 

    'Telerik.Sitefinity.Security.Model.UserProfile' does not contain a definition for 'GetValue' and no extension method 'GetValue' accepting a first argument of type 'Telerik.Sitefinity.Security.Model.UserProfile' could be found (are you missing a using directive or an assembly reference?) 

    I've checked the version of my Telerik.Sitefinity.dll and it is 4.1.1339.0

    Any ideas?

    Regards,

      Peter

  5. j8
    j8 avatar
    20 posts
    Registered:
    30 Oct 2007
    21 Apr 2011
    Link to this post

    I figured it out;

          UserManager userManager = UserManager.GetManager();
          User user = userManager.GetUser(HttpContext.Current.User.Identity.Name);
          UserProfileManager userProfileManager = UserProfileManager.GetManager();
          UserProfile profile = userProfileManager.GetUserProfile(user.Id, typeof(SitefinityProfile).FullName);
          var v = Telerik.Sitefinity.Model.DataExtensions.GetValue(profile, "School");
          //var v = profile.GetValue("School");
    
    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

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    21 Apr 2011
    Link to this post
    Hello j8,

    You can add reference to "Telerik.Sitefinity.Model.DataExtensions". GetValue is an extension method.

    Regards,
    Ivan Dimitrov
    the Telerik team

  7. j8
    j8 avatar
    20 posts
    Registered:
    30 Oct 2007
    21 Apr 2011
    Link to this post
    Hi Ivan,

    Yeah I saw that mentioned before. By "adding reference to" you mean a ?

    using Telerik.Sitefinity.Model.DataExtensions;
    


    This gives me a

    Error 1 A using namespace directive can only be applied to namespaces; 'Telerik.Sitefinity.Model.DataExtensions' is a type not a namespace 

    Or is "adding a reference to" something other than a using clause?

    Regards,
      Peter
  8. Amanda Shafer
    Amanda Shafer avatar
    198 posts
    Registered:
    12 Oct 2012
    21 Apr 2011
    Link to this post
    Peter, I got it to work through a combination of things:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Sitefinity.Security;
    using Telerik.Sitefinity.Security.Model;
      
    namespace SitefinityWebApp.UserControls.LoginInfo
    {
        public partial class ProfileInfo : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                UserManager manager = UserManager.GetManager();
                User user = manager.GetUser(HttpContext.Current.User.Identity.Name);
      
                var pm1 = UserProfileManager.GetManager();
                var p1 = pm1.GetUserProfile(user.Id, typeof(SitefinityProfile).FullName);
                var value1 = Telerik.Sitefinity.Model.DataExtensions.GetValue(p1, "memberID");
      
                lblInfo.Text = value1 as string;
            }
      
              
        }
    }
  9. j8
    j8 avatar
    20 posts
    Registered:
    30 Oct 2007
    02 May 2011
    Link to this post

    Duh!

    for anyone interested;

    This did the job;

    using Telerik.Sitefinity.Model;

    You can then use;

    UserProfile profile = userProfileManager.GetUserProfile(sitefinityUser.Id, typeof(SitefinityProfile).FullName);
    schoolName = profile.GetValue("School").ToString();

    Regards,

      Peter 

  10. Aakash
    Aakash avatar
    2 posts
    Registered:
    19 Jan 2015
    27 Jul
    Link to this post

    Is it possible to access (get and put) custom field using RestAPI?

    - http://sitefinity_website/Sitefinity/Services/Security/Users.svc

10 posts, 1 answered