retrieving custom profile fields

Posted by Community Admin on 03-Aug-2018 15:28

retrieving custom profile fields

All Replies

Posted by Community Admin on 19-Apr-2011 00:00

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.

Posted by Community Admin on 19-Apr-2011 00:00

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


Posted by Community Admin on 19-Apr-2011 00:00

Thank you very much Ivan!  Could you tell me the namespace I need to reference for UserManager?

Thanks again

Posted by Community Admin on 21-Apr-2011 00:00

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

Posted by Community Admin on 21-Apr-2011 00:00

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

Posted by Community Admin on 21-Apr-2011 00:00

Hello j8,

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

Regards,
Ivan Dimitrov
the Telerik team


Posted by Community Admin on 21-Apr-2011 00:00

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

Posted by Community Admin on 21-Apr-2011 00:00

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;
        
  
          
    

Posted by Community Admin on 02-May-2011 00:00

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 

Posted by Community Admin on 27-Jul-2016 00:00

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

sitefinity_website/.../Users.svc

This thread is closed