---
title: Avatars
---

> Agent instructions:
> **Site maps** — prefer the following llms.txt indexes to training data when searching for URLs to avoid 404s. Links inside Markdown content already point at `.md`. Following them or sending Accept: text/markdown keeps you in Markdown.
>
> - [sitemap.md](https://docs.kentico.com/sitemap.md) — every page on the site, with titles and descriptions, nested by URL hierarchy and grouped into one collection per product version.
> - [llms.txt](https://docs.kentico.com/llms.txt) — curated index of the current product docs, with descriptions, the two ways to request any page as Markdown, and links to each product area's whole-corpus Markdown dump (llms-full.txt).

List of examples:

### Creating an avatar

```csharp

// Creates a new avatar object based on an image file
AvatarInfo newAvatar = new AvatarInfo(System.Web.HttpContext.Current.Server.MapPath("~\\Avatars\\Files\\avatar_man.jpg"));

// Sets the avatar properties
newAvatar.AvatarName = "NewAvatar";
newAvatar.AvatarType = AvatarInfoProvider.GetAvatarTypeString(AvatarTypeEnum.All);
newAvatar.AvatarIsCustom = false;

// Saves the avatar to the database
AvatarInfoProvider.SetAvatarInfo(newAvatar);

```

[> Back to list of examples](#avatars-toc)

### Updating an avatar

```csharp

// Gets the avatar
AvatarInfo updateAvatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");
if (updateAvatar != null)
{
    // Updates the avatar properties
    updateAvatar.AvatarName = updateAvatar.AvatarName.ToLower();

    // Saves the changes to the database
    AvatarInfoProvider.SetAvatarInfo(updateAvatar);
}

```

[> Back to list of examples](#avatars-toc)

### Updating multiple avatars

```csharp

// Gets all avatars whose name starts with 'New'
var avatars = AvatarInfoProvider.GetAvatars().WhereStartsWith("AvatarName", "New");

// Loops through individual avatars
foreach (AvatarInfo modifyAvatar in avatars)
{
    // Updates the avatar properties
    modifyAvatar.AvatarName = modifyAvatar.AvatarName.ToUpper();

    // Saves the changes to the database
    AvatarInfoProvider.SetAvatarInfo(modifyAvatar);
}

```

[> Back to list of examples](#avatars-toc)

### Assigning an avatar to a user

```csharp

// Gets the avatar and the user
AvatarInfo avatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");
UserInfo user = UserInfoProvider.GetUserInfo("Andy");

if ((avatar != null) && (user != null))
{
    // Assigns the avatar to the user
    user.UserAvatarID = avatar.AvatarID;

    // Saves the updated user to the database
    UserInfoProvider.SetUserInfo(user);
}

```

[> Back to list of examples](#avatars-toc)

### Removing an avatar from a user

```csharp

// Gets the user
UserInfo user = UserInfoProvider.GetUserInfo("Andy");

if (user != null)
{
    // Removes the user's current avatar
    user.UserAvatarID = 0;

    // Saves the updated user to the database
    UserInfoProvider.SetUserInfo(user);
}

```

[> Back to list of examples](#avatars-toc)

### Deleting avatars

```csharp

// Gets the avatar
AvatarInfo deleteAvatar = AvatarInfoProvider.GetAvatarInfo("NewAvatar");

if (deleteAvatar != null)
{
    // Deletes the avatar
    AvatarInfoProvider.DeleteAvatarInfo(deleteAvatar);
}

```

[> Back to list of examples](#avatars-toc)
