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

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Programatically update user profile informationProgramatically update user profile information
Previous
 
Next
New Post
7/6/2009 8:00 PM
 

Hey everyone, I'm on DNN 5.1 and I've been trying to get this to work for about 2 weeks now. It seems there aren't many tutorials online for this particular bit. I'm basically trying to be able to get and set user profile properties such as name, email, phone and a few custom properties that have been added.

This is essentially what I am doing that isn't working

DotNetNuke.Entities.Users.UserInfo CurUser = new DotNetNuke.Entities.Users.UserInfo();

CurUser.Profile.InitialiseProfile(this.PortalID);

CurUser.Username = this.UserName;

CurUser.UserID = this.UserID;

CurUser.Profile.SetProfileProperty("FirstName", this.FirstName);

CurUser.Profile.SetProfileProperty("CustomField", this.CustomField);

DotNetNuke.Entities.Users.UserController.UpdateUser(this.PortalID, CurUser);

DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile(CurUser);

 

I usually get an error saying something like "Object reference not set to an instance of an object", which I don't believe is true. I'm not sure if I'm being vague or leaving anything out, but if anyone could help me out that would be super.

 

Thanks,

Stefan

 

 
New Post
7/7/2009 6:16 PM
 

Excuse me, I meant DNN version 5.0.1.  Can anyone point me in the right direction on this one please?

 
New Post
7/8/2009 10:41 PM
 

Which line is causing issues?  Off the top of my head your code looks ok.


Philip Beadle - Employee
 
New Post
7/9/2009 5:36 PM
 

 Hey Philip,

thanks for the help. :)

Well I found that my problem was that for some reason the username and userid weren't getting properly passed to the above code, but now are. I'm still have problems though.  No errors are thrown, but when I go to update the profile, only certain fields are updated (firstname, lastname and email) which I've noticed are the only fields accessible by DotNetNuke.Entities.Users.UserInfo(), the other profile fields are one level deeper in the Profile class of the UserInfo class. I'm not sure why those fields aren't updating, the same problem persists for my custom fields.

 

DotNetNuke.Entities.Users.UserInfo CurUser = new DotNetNuke.Entities.Users.UserInfo();

CurUser.Profile.InitialiseProfile(PortalID);

CurUser.Username = UserName;

CurUser.UserID = UserID;

CurUser.FirstName = FirstName; //Updates

CurUser.LastName = LastName; //Updates

CurUser.Profile.City = City; //Doesn't update

 

CurUser.Email = Email; //Updates

CurUser.Profile.SetProfileProperty("RecurID", RecurID.ToString());  //Custom Field Doesn't update

DotNetNuke.Entities.Users.UserController.UpdateUser(PortalID, CurUser);

DotNetNuke.Entities.Profile.ProfileController.UpdateUserProfile(CurUser);

 

Any Ideas??

Thanks alot!

Stefan V Ott

 
New Post
7/9/2009 11:06 PM
 

I believe the problem lies with the manner in which you are initializing CurUser. Assuming that you are updating profile properties for an already existing user, instead of calling the constructor for a new UserInfo object, you should be getting a UserInfo object for an existing user by either the UserID or Username. This insures that the profile property collection is properly hydrated and in particular its isHydrated and isDirty flags are appropriately set. I would try the following:

DotNetNuke.Entities.Users.UserInfo CurUser = DotNetNuke.Entities.Users.UserController.GetUser(PortalID, UserID, False);
CurUser.FirstName=FirstName;
CurUser.LastName=LastName;
CurUser.Profile.City=City;
CurUser.Email=EMail;
CurUser.Profile.SetProfileProperty("RecurID", RecurID.ToString());
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalID, CurUser);

Note that since UpdateUser calls UpdateUserProfile if any of the profile properties are dirty, the call to UpdateUserProfile is not needed.

If, on the otherhand, you are creating a new user, it will be necessary to call the CreateUser static method of the UserController.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Programatically update user profile informationProgramatically update user profile information


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