More in this section

Forums / Developing with Sitefinity / Querying by custom user profile fields

Querying by custom user profile fields

2 posts, 0 answered
  1. Rich
    Rich avatar
    24 posts
    22 Oct 2012
    24 Jan 2014
    Link to this post
    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?
  2. Rein
    Rein avatar
    22 posts
    07 Oct 2008
    27 Jan 2014 in reply to Rich
    Link to this post
    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>();
2 posts, 0 answered