Kentico CMS 6.0 Developer's Guide

Managing user avatars

Managing user avatars

Previous topic Next topic Mail us feedback on this topic!  

Managing user avatars

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example assigns an avatar to a specific user.

 

private bool 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);
 
        return true;
    }
 
    return false;
}

 

The following example removes a user's avatar.

 

private bool RemoveAvatarFromUser()
{
    // Get the user
    UserInfo user = UserInfoProvider.GetUserInfo(CMSContext.CurrentUser.UserName);
 
    if (user != null)
    {
        user.UserAvatarID = 0;
 
        // Save edited object
        UserInfoProvider.SetUserInfo(user);
 
        return true;
    }
 
    return false;
}