Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan Evans 616 posts 988 karma points
    Aug 02, 2013 @ 16:43
    Dan Evans
    0

    Saving custom member properties via API

    Using Umbraco 6.0.5 I am trying to save some custom member properties via the API. The new member is created fine but the custom properties are not saved. I have checked that the properties exist. In fact if the property name is changed to one that does not exist an error is thrown:

     public override void Submit()
            {
                //get a membertype by its alias
                var mt = MemberType.GetByAlias(MemberTypeAlias); //needs to be an existing membertype
                //get the user(0)
                var user = new User(0);
                //create a new member with Member.MakeNew
                var member = Member.MakeNew(Name, mt, user);
                //assign email, password and loginname
                member.Email = Email;
                member.Password = Password;
                member.LoginName = Email;
                //asign custom properties
                member.getProperty("committee").Value = Committee;
                member.getProperty("organisation").Value = Organisation;
                
                //asssign a group, get the group by name, and assign its Id
                var group = MemberGroup.GetByName(MemberGroupName); //needs to be an existing MemberGroup
                member.AddGroup(group.Id);
                //generate the member xml with .XmlGenerate
                member.XmlGenerate(new System.Xml.XmlDocument());
                //add the member to the website cache to log the member in
                Member.AddMemberToCache(member);
            }

     

  • Ali Sheikh Taheri 470 posts 1647 karma points c-trib
    Aug 02, 2013 @ 18:50
    Ali Sheikh Taheri
    102

    you need to call

    member.save();
    

    for older version that was not mandatory but for umbraco 6 and above you have to call save method in order to save the properties.

  • Charles Afford 1163 posts 1709 karma points
    Aug 06, 2013 @ 12:32
  • Charles Afford 1163 posts 1709 karma points
    Aug 06, 2013 @ 12:33
    Charles Afford
    0

    You also need to make sure the Name and Alias are diffrent :).

  • Dan Evans 616 posts 988 karma points
    Aug 06, 2013 @ 14:37
    Dan Evans
    0
    member.save();
    Did it. Thank you!
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies