Christian Bekker
Christian Bekker

Reputation: 1867

Get properties from Members in Umbraco (In Usercontrol)

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...

Upvotes: 6

Views: 5733

Answers (2)

Ankur Ghelani
Ankur Ghelani

Reputation: 659

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;
}

Upvotes: 2

Goran Mottram
Goran Mottram

Reputation: 6304

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

Upvotes: 0

Related Questions