// Create new avatar object AvatarInfo newAvatar = newAvatarInfo(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.
privatebool 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); returntrue; } returnfalse; }
The following example gets and bulk updates avatars.
privatebool 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 = newAvatarInfo(avatarDr); // Update the properties modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper(); // Save the changes AvatarInfoProvider.SetAvatarInfo(modifyAvatar); } returntrue; } returnfalse; }
The following example deletes an avatar.
privatebool DeleteAvatar() { // Get the avatar AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("MyNewAvatar"); // Delete the avatar AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar); return (deleteAvatar != null); }