retrieving custom profile fields
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:
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");
the Telerik team
Thank you very much Ivan! Could you tell me the namespace I need to reference for UserManager?
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
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");
You can add reference to "Telerik.Sitefinity.Model.DataExtensions". GetValue is an extension method.
the Telerik team
Yeah I saw that mentioned before. By "adding reference to" you mean a ?
Peter, I got it to work through a combination of things:
for anyone interested;
This did the job;
You can then use;
UserProfile profile = userProfileManager.GetUserProfile(sitefinityUser.Id, typeof(SitefinityProfile).FullName); schoolName = profile.GetValue("School").ToString();
Is it possible to access (get and put) custom field using RestAPI?