Get properties from Members in Umbraco (In Usercontrol)
Asked Answered
B

2

6

I've made a Umbraco site, and ive got some members that i need to display information about in a usercontrol(ascx) page. But the only thing i can find is the old umbraco api, with the m.GetProperty(); method like:

foreach (Member m in Member.GetAll) {
    m.getProperty("danceStyles");
}

But visual studio says that Member is obsolete and i should use Membership instead, but i dont know how i can get generic properties from a member through that. Only thing i can get is Username, Email and Password, and not properties i define in umbraco...

Burra answered 21/12, 2012 at 8:24 Comment(0)
E
2

Yah, Member.GetAll is obsolete but I suppose you could use Member.GetAllAsList() this method is to get members in List, This method works for me

foreach (var member in Member.GetAllAsList())
{
    // to get Property
    var property = member.getProperty("danceStyles");

    // to get Property Value
    var propertyValue = member.getProperty("danceStyles").Value;
}
Especial answered 21/12, 2012 at 12:10 Comment(1)
Worked like a charm! thought it was the whole Member class that was obsolete so didn't even think of using that!Burra
S
0

Default properties of a member, such as Login, Email and Password can easily be referenced through .Net properties, however as you've noticed, custom properties can only be accessed by string.

The getProperty() method returns an umbraco.cms.businesslogic.property.Property object, so if you want to get/set the actual values of custom properties you've made, simply access the Value [.net] property of the [umbraco] property like so:

m.getProperty("danceStyles").Value
Sheila answered 21/12, 2012 at 11:49 Comment(1)
I've not played around with the Membership library yet, so perhaps someone could provide a more "up-to-date" answer.Sheila

© 2022 - 2024 — McMap. All rights reserved.