I am trying to create a member with the following code. What currently happens is that the member will be created in the database put an exception is thrown on the line [_member.getProperty("FirstName").Value = FirstName.Text;] as getProperty seems to return null.
I have a FirstName property on the "Subscriber" member type in a Tab called personal details but for some reason this is not getting picked up by Umbraco.
Create a member with custom MemberType properties
Hi,
I am trying to create a member with the following code. What currently happens is that the member will be created in the database put an exception is thrown on the line [_member.getProperty("FirstName").Value = FirstName.Text;] as getProperty seems to return null.
I have a FirstName property on the "Subscriber" member type in a Tab called personal details but for some reason this is not getting picked up by Umbraco.
Thanks in advance,
B
public void Create()
{
MemberType memberType = MemberType.GetByAlias(MemberTypeConstants.Subscriber);
MemberGroup memberGroup = MemberGroup.GetByName(MemberGroupConstants.RetirementSavingPlanner);
_member = Member.MakeNew(EmailAddress.Text, memberType, new umbraco.BusinessLogic.User(0)); _member.Email = EmailAddress.Text;
_member.Password = Password.Text;
_member.LoginName = EmailAddress.Text;
// Generate member Xml Cache
_member.XmlGenerate(new System.Xml.XmlDocument());
_member.getProperty("FirstName").Value = FirstName.Text;
_member.getProperty("LastName").Value = LastName.Text;
_member.AddGroup(memberGroup.Id);
_member.Save();
}
This seems legit code. Have a look at Tim's blogpost about creating members as well, might give you some clues.
The only problem I can think of right now is that the alias "FirstName" does not have the same casing as in Umbraco's backend, have you checked that?
Turns out I was using the wrong case for the property it should have been camalCase.
I had one of those head slap moments when I noticed this.
is working on a reply...