Kentico CMS 6.0 Developer's Guide

Managing avatars

Managing avatars

Previous topic Next topic Mail us feedback on this topic!  

Managing 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 creates an avatar.

 

private void CreateAvatar()
{

  // Create new avatar object
  AvatarInfo newAvatar = new AvatarInfo(Server.MapPath("~\\CMSAPIExamples\\Code\\Community\\Avatars\\Files\\avatar_man.jpg"));

 
  // Set the properties
   newAvatar.AvatarName = "MyNewAvatar";
   newAvatar.AvatarType = AvatarInfoProvider.GetAvatarTypeString(AvatarTypeEnum.All);
   newAvatar.AvatarIsCustom = false;

 
    // Save the avatar
    AvatarInfoProvider.SetAvatarInfo(newAvatar);
}

 

The following example gets and updates an avatar.

 

private bool GetAndUpdateAvatar()
{
    // Get the avatar
    AvatarInfo updateAvatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar");
    if (updateAvatar != null)
    {
        // Update the properties
        updateAvatar.AvatarName = updateAvatar.AvatarName.ToLower();
 
        // Save the changes
        AvatarInfoProvider.SetAvatarInfo(updateAvatar);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates avatars.

 

private bool GetAndBulkUpdateAvatars()
{
    // Prepare the parameters
    string where = "AvatarName LIKE N'MyNewAvatar%'";
 
    // Get the data
    DataSet avatars = AvatarInfoProvider.GetAvatars(where, null);
    if (!DataHelper.DataSourceIsEmpty(avatars))
    {
        // Loop through the individual items
        foreach (DataRow avatarDr in avatars.Tables[0].Rows)
        {
            // Create object from DataRow
            AvatarInfo modifyAvatar = new AvatarInfo(avatarDr);
 
            // Update the properties
            modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper();
 
            // Save the changes
            AvatarInfoProvider.SetAvatarInfo(modifyAvatar);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes an avatar.

 

private bool DeleteAvatar()
{
    // Get the avatar
    AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar");
 
    // Delete the avatar
    AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar);
 
    return (deleteAvatar != null);
}