Writing first user control to list members - problem with getProperty Options
awaegel
Posted: Thursday, October 30, 2008 1:34:42 AM
Rank: Newbie

Joined: 6/28/2008
Posts: 9
Hello,

I'm bravely writing my first umbraco user control (umbraco.tv video was a great help) which will eventually be a member search.

I'm able to fetch all the members and some of their built-in values like Email, but I can't figure out how to use the getProperty method to get a custom member field. Seems like it should be easy from googling examples, but i get an 'Object reference not set to an instance of an object' error with this code:

Code:


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ResultsField.Text = "Type above and go";
            }

            foreach (umbraco.cms.businesslogic.member.Member m in
                umbraco.cms.businesslogic.member.Member.GetAll)
            {
                ResultsField.Text += m.getProperty("RegionServed").Value; // throws the error
                ResultsField.Text += m.Email; // works fine
            }

        }


I'm sure 'RegionServed' is the correct alias of my Member property.

Any ideas? Be nice, I'm a former PHP coder and so far C# is a cruel mistress :)

leekelleher
Posted: Thursday, October 30, 2008 2:12:25 AM

Rank: Enthusiast

Joined: 5/28/2008
Posts: 45
Location: Bristol, UK
Hi Andrew,

Without knowing the properties for your member type, it sounds like either the alias name is wrong, or the property doesn't exist.

A simple way to identify this is to get the Property object first, before calling the .Value:

Code:

foreach (Member m in Member.GetAll)
{
    Property p= m.getProperty("RegionServed");
    if (p != null)
    {
        ResultsField.Text += p.Value;
        ResultsField.Text += m.Email;
    }
    else
    {
        // do something with members that don't have the "RegionServed" property
    }
}


Hope this helps.

Cheers,
- Lee

PS. I saw your reply on the other forum topic about Member Search. I'll get around to posting some code soon; (got a project deadline for Friday - so working around the clock until then) Boo hoo!

http://leekelleher.com/
awaegel
Posted: Thursday, October 30, 2008 6:03:17 AM
Rank: Newbie

Joined: 6/28/2008
Posts: 9
Thanks, that worked perfectly - the RegionServed property simply wasn't set for one of my Members, so .NET threw an error when I tried to access its value.
Users browsing this topic
Guest


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.