Creating a new user in code

rated by 0 users
This post has 8 Replies | 2 Followers

Not Ranked
Posts 6
Points 75
geoffwebb Posted: Mon, Sep 25 2006 1:08 PM

I having a problem creating new users as part of a CSJob I've created.  The problem is that I get a NullReference exception when I create the user. The code in question is as follows:

Dim usr As New User

usr.AccountStatus = UserAccountStatus.Approved
usr.Username = "Delgeate123443"
usr.EnableDisplayName = True
usr.Email = "tester1@ptpprograms.org"
 
Try
     Users.Create(usr, False)
Catch ex As Exception
     Throw ex
End Try

Any thoughts?

Top 25 Contributor
Posts 2,115
Points 27,605
MVPs
Please set a password for user to see what will happen.
  • | Post Points: 20
Not Ranked
Posts 6
Points 75
geoffwebb replied on Mon, Sep 25 2006 5:05 PM
I tried that, and got the same error.  The error seems to be occuring in the data provider. I'm going to look at the source code and see what I can find out.
  • | Post Points: 5
Not Ranked
Posts 6
Points 75
geoffwebb replied on Tue, Sep 26 2006 1:21 PM
I figured it out. IsAnonymous needs to be set to true.
  • | Post Points: 20
Not Ranked
Posts 2
Points 40

Hi Guys,

I am attempting to create a cs2007 user as part of a job and I am getting the following exception:

Object reference not set to an instance of an object

and my code looks like this:

public class ImportUsersJob : ITask

{

public void Execute(System.Xml.XmlNode node)

{

User user;user = new User();

 

user.AccountStatus = CommunityServer.Components.UserAccountStatus.Approved;

user.Username = "matt";

user.Password = "pass99T";

user.Email = "matt@hotmail.com";

user.IsAnonymous = true;

CommunityServer.Users.Create(user, false);

}

}

 

Is there something that I have to do in order to be allowed to execute this code?

Thanks,

Matt

 

Top 500 Contributor
Posts 59
Points 880
rfritts replied on Fri, Jun 15 2007 12:24 PM

sorry for the double post... :'(

  • | Post Points: 5
Top 500 Contributor
Posts 59
Points 880
rfritts replied on Fri, Jun 15 2007 12:28 PM

Just a question... Is there any particular reason you are setting IsAnonymous to true? Just because it makes it work in some instances doesn't mean that it should necessarily be done.  What if the user doesn't want to be anonymous?

Perhaps you could take a peak at the CreateUserForm...

I believe you might want to set IsAnonymous -> False, AccountStatus -> UserAccountStatus.Approved,

  • | Post Points: 20
Not Ranked
Posts 2
Points 40

rfritts:

Just a question... Is there any particular reason you are setting IsAnonymous to true? Just because it makes it work in some instances doesn't mean that it should necessarily be done.  What if the user doesn't want to be anonymous?

Perhaps you could take a peak at the CreateUserForm...

I believe you might want to set IsAnonymous -> False, AccountStatus -> UserAccountStatus.Approved,

 

 
Thanks mate, 

It seems it was as simple as setting the IsAnonymous to false and it all worked!

Thanks,

 
Matt
 

Page 1 of 1 (9 items) | RSS
Powered by Community Server (Commercial Edition), by Telligent Systems

Copyright© 2008 Telligent Systems Inc. All rights reserved
CommunityServer.com  •  Telligent.com