Question

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?

Was it helpful?

Solution

        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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top