Deleting user profiles

The following examples represent the deleting of user profiles separately from the deleting of the users. For more information, see the Deleting users example. The examples describe how to delete a single user profile or all user profiles of type SitefinityProfile.

Deleting a single user profile

To delete a profile, you must get an instance of the profile. In this examples you get an instance of the profile by the ID of the user. For more information, see Querying user profiles. Then, you call the DeleteProfile method of the manager. Finally, you save the changes.

public static void DeleteUserProfile(Guid userId)
{
    UserProfileManager profileManager = UserProfileManager.GetManager();
    UserManager userManager = UserManager.GetManager();
 
    User user = userManager.GetUser(userId);
 
    if (user != null)
    {
        SitefinityProfile profile = profileManager.GetUserProfile<SitefinityProfile>(user);
 
        profileManager.Delete(profile);
 
        profileManager.SaveChanges();
    }
} 

Deleting all user profiles

To delete all profiles of type SitefinityProfile, you call the DeleteProfilesForProfileType method and pass the SitefinityProfile as a type.

public static void DeleteAllUserProfiles()
{
    UserProfileManager profileManager = UserProfileManager.GetManager();
 
    profileManager.DeleteProfilesForProfileType(typeof(SitefinityProfile));
 
    profileManager.SaveChanges();
}

Next steps

+1-888-365-2779
sales@sitefinity.com

Related topics:

Feedback

How useful is this article?

Tell us more

Submit
Your message was successfully sent.

We appreciate your feedback.

Your message could not be sent.

OK