Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUpdate a custom profile property of the specific user programmaticallyUpdate a custom profile property of the specific user programmatically
Previous
 
Next
New Post
1/15/2010 7:37 AM
 

Hi,

I just created a custom profile property in Host --> User Accounts --> AddNewProperty called Gender( for example ).  Now, what I want to do is edit this custom property programmatically for a specific user so I tried this code.

UserController objUserController = new UserController();
                    UserInfo objUserInfo = objUserController.GetUser(0, 222);
                    ProfilePropertyDefinitionCollection objProfile = ProfileController.GetPropertyDefinitionsByPortal(PortalId);
                    for (int x = 0; x < objProfile.Count; x++)
                    {
                        string pName = objProfile[x].PropertyName;
                        if (objUserInfo.Profile.ProfileProperties[x].PropertyName == "Gender")
                            objUserInfo.Profile.ProfileProperties[x].PropertyValue = "Male";

                       
                    }
                    UserController.UpdateUser(PortalId, objUserInfo);
                    ProfileController.UpdateUserProfile(objUserInfo);
 

When i try to debug this code, I can see that the value of Gender for user 222 is being changed from Null to male but when I looked at the UserProfile tables, I cannot see that the Gender  of user 222 has not been updated.  How am I suppose to save the changes.

I already have tried UpdateUser and UpdateUserProfile but it doesn't seem to work...

Does anyone know?

Thanks!

 

 

 

 

 
New Post
1/15/2010 2:51 PM
Accepted Answer 

Hi Mysteria,

You'll want to use the SetProfileProperty of the Profile object to make this change.  Once it is made, you'll need to call UserController.UpdateUser to persist the changes.  For example:

  user.Profile.SetProfileProperty("Gender", "Male");
  UserController.UpdateUser(user.PortalId, user);

Hope this helps!

Brandon


Brandon Haynes
BrandonHaynes.org
 
New Post
1/17/2010 10:34 PM
 

Hello Brandon,

That is exactly what I'm looking for.  Thank you so much.. :) 

~Mysteria

 

 

 

 
New Post
1/9/2014 6:34 AM
 

Hi,

 I know this thread is an old one but I am having the same problem.  I have posted on several forums but still don't have a solution.  I have tried what you suggested but to no joy.  I think the only difference here is the version of DNN, we're using version 7.0.6.   My code is very similar to the OP but custom profile properties are not saving.  And ideas??

 Any help would be greatly appreciated.

Thanks

 Jay

 
New Post
8/23/2015 9:52 PM
 
I was having this same issue and Brandon's fix worked like a charm for me!


Ralph Williams, Jr.
UX Designer / Front-End Web Developer
www.RalphWilliams.com
Ralph Williams Consulting
Twitter: twitter.com/ralphwilliams

Professional DNN7: Open Source .NET CMS Platform
 
Previous
 
Next
HomeHomeDevelopment and...Development and...Building ExtensionsBuilding ExtensionsModulesModulesUpdate a custom profile property of the specific user programmaticallyUpdate a custom profile property of the specific user programmatically


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out