private
void
AddUser()
{
DotNetNuke.Entities.Users.UserInfo objUser =
new
DotNetNuke.Entities.Users.UserInfo();
objUser.AffiliateID = Null.NullInteger;
objUser.Email =
"user@email.com"
;
objUser.FirstName =
"FirstName"
;
objUser.IsSuperUser =
false
;
//I bet you will not create SuperUsers
in
bulk ;)
objUser.LastName =
"LastName"
;
objUser.PortalID =
this
.PortalId;
objUser.Username =
"UserName"
;
objUser.DisplayName =
"Display Name"
;
//Usually here FirstName+LastName
objUser.Membership.Password =
"your_password"
;
//please check
in
web.config requirements
for
your password (length, letters, etc)
objUser.Membership.Approved =
true
;
objUser.Membership.Email =
"user@email.com"
;
objUser.Membership.Username = objUser.Username;
objUser.Membership.UpdatePassword =
true
;
//this
one needs
if
you want user to update password on first login, else set to false
objUser.Profile.Country =
"Your Country"
;
objUser.Profile.Street =
"Street"
;
objUser.Profile.City =
"City"
;
objUser.Profile.Region =
"Region"
;
objUser.Profile.PostalCode =
"PostalCode"
;
objUser.Profile.Unit =
"Unit"
;
objUser.Profile.Telephone =
"Telephone"
;
objUser.Profile.FirstName = objUser.FirstName;
objUser.Profile.LastName = objUser.LastName;
DotNetNuke.Security.Membership.UserCreateStatus objCreateStatus =
DotNetNuke.Entities.Users.UserController.CreateUser(
ref
objUser);
if
(objCreateStatus == DotNetNuke.Security.Membership.UserCreateStatus.Success)
{
//everything fine
}
else
{
//simple show error
lblError.Text = objCreateStatus.ToString();
}
}
Hope this helps!
greetings,
ReplyDeleteI am getting an obsolete warning when adding in objUser.Membership.Username = objUser.Username; in DNN 6. Do you know the new way in DNN6?
Thanks!
Jay Stratemeyer
objUser.Membership = new UserMembership(objUser);
DeleteThis sets those properties and others that were deprecated, within the constructor of UserMembership
Hi,
ReplyDeleteI'm getting a couple errors that say that the name "Null", doesn't exist in the current context, and lblErrors doesn't exist in the current context either. If you could help that would be great!
Thank You!
Turner Bell
Null goes from the DotNetNuke.Common.Utilites namespace. lblErrors - just a asp:Label on the form. Hope this helps.
ReplyDeletethanks alot , you really helped me a lot :*
ReplyDeleteHi,
ReplyDeleteI am using above code to create user and profile.
User created successfully. when i get user info by id, i do not get profile data.
I checked userprofile table there data store enter by me.
I am not sure why profile info not come on get user.
Kindly let me know how to fix it.
Regards,
Vikash
What version of DNN do you use?
DeleteI am using DNN 9.2 Version
DeleteThis example was for 7.x version.
Delete