Tuesday, February 28, 2012

DotNetNuke Update Custom Profile fields

I had a good bit of trouble with this, but I was able to get it working.

You may need to make sure the custom property you have created is marked Visible, but this is the code that ended up working for me in DNN 6.1.2.

UserInfo _currentUser = DotNetNuke.Entities.Users.UserController.GetCurrentUserInfo();
// Create Token
string sessionGuid = TokenLibrary.TokenSupport.CreateToken(_currentUser).ToString();
if (sessionGuid == null || (sessionGuid.Trim().Length < 1 )
sessionGuid = "00000000-0000-0000-0000-000000000000";
// Set User Property called "sessionGUID"
_currentUser.Profile.SetProfileProperty("sessionGUID", sessionGuid);
UserController.UpdateUser(_currentUser.PortalID, _currentUser);