The following example assigns an avatar to a specific user.
privatebool AddAvatarToUser() { // Get the avatar and user objects AvatarInfo avatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar"); UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName); if ((avatar != null) && (user != null)) { user.UserAvatarID = avatar.AvatarID; // Save edited object UserInfoProvider.SetUserInfo(user); returntrue; } returnfalse; }
The following example removes a user's avatar.
privatebool RemoveAvatarFromUser() { // Get the user UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName); if (user != null) { user.UserAvatarID = 0; // Save edited object UserInfoProvider.SetUserInfo(user); returntrue; } returnfalse; }