views:

54

answers:

1

Given a profile field I store with each user the following way:

Context.Profile.SetPropertyValue("IsSubscribed", isSubscribed.Checked);
Context.Profile.Save();

How would I on another page fetch all users email addresses where isSubscribed = true?

+1  A: 
        List<String> subscribedEmails = new List<String>();

        ProfileInfoCollection profiles = ProfileManager.GetAllProfiles(ProfileAuthenticationOption.All);

        foreach (ProfileInfo profileInfo in profiles)
        {
            ProfileBase profile = ProfileBase.Create(profileInfo.UserName);
            if ((bool)profile.GetPropertyValue("IsSubscribed"))
            {
                subscribedEmails.Add((string)profile.GetPropertyValue("Email"));
            }
        }

Edit: To get the user's email address from the membership system use:

subscribedEmails.Add(Membership.GetUser(profileInfo.UserName).Email);
kevev22
Super answer thank you! But the email is stored with the membership system I think, how do I access this? The email isn't a property associated with the profile system
Tom Gullen
Hmm it's also not seeming to return records at all when the value definatly is true...
Tom Gullen
I am not sure why it isn't returning records for you. Are you using a custom profile provider?
kevev22