Querying by custom user profile fields

Posted by Community Admin on 04-Aug-2018 18:25

Querying by custom user profile fields

All Replies

Posted by Community Admin on 24-Jan-2014 00:00

I've added some custom user profile fields to my Basic profile type.  I'd like to be able to query user profiles based on the data in these custom fields.  I feel like I've looked all over for a solution.  Is there a way to do this?

Posted by Community Admin on 27-Jan-2014 00:00

Check out the code below. Make sure you change "MyCustomField" and "MyQuery" so that it will reflect your custom field and query respectively.

var profileManager = UserProfileManager.GetManager();
var sfProfiles = SitefinityQuery.Get<UserProfile>(typeof(SitefinityProfile), profileManager.Provider)
                                .Where(p => p.ApplicationName == profileManager.Provider.ApplicationName);
 
sfProfiles = sfProfiles.Where(x => x.GetValue<string>("MyCustomField").Contains("MyQuery"));
 
var profiles = sfProfiles.Cast<SitefinityProfile>();

This thread is closed