Querying by custom user profile fields
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?
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>();