---
title: Countries
---

> 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:

## Countries

### Creating a new country

```csharp

// Creates a new country object
CountryInfo newCountry = new CountryInfo();

// Sets the country properties
newCountry.CountryDisplayName = "New country";
newCountry.CountryName = "NewCountry";

// Saves the new country into the database
CountryInfoProvider.SetCountryInfo(newCountry);

```

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

### Updating an existing country

```csharp

// Gets the country
CountryInfo updateCountry = CountryInfoProvider.GetCountryInfo("NewCountry");
if (updateCountry != null)
{
    // Updates the country properties
    updateCountry.CountryDisplayName = updateCountry.CountryDisplayName.ToLower();

    // Saves the change to the database
    CountryInfoProvider.SetCountryInfo(updateCountry);
}

```

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

### Updating multiple countries

```csharp

// Gets all countries whose name starts with 'NewCountry'
var countries = CountryInfoProvider.GetCountries().WhereStartsWith("CountryName", "NewCountry");

// Loops through individual countries
foreach (CountryInfo country in countries)
{                   
    // Updates the country properties
    country.CountryDisplayName = country.CountryDisplayName.ToUpper();

    // Saves the change to the database
    CountryInfoProvider.SetCountryInfo(country);
}

```

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

### Deleting a country

```csharp

// Gets the country
CountryInfo deleteCountry = CountryInfoProvider.GetCountryInfo("NewCountry");

if (deleteCountry != null)
{
    // Deletes the country
    CountryInfoProvider.DeleteCountryInfo(deleteCountry);
}

```

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

## States

### Creating a new state under a country

```csharp

// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("NewCountry");
if (country != null)
{
    // Creates a new state object
    StateInfo newState = new StateInfo();

    // Sets the state properties
    newState.StateDisplayName = "New state";
    newState.StateName = "NewState";
    newState.CountryID = country.CountryID;

    // Saves the new state into the database
    StateInfoProvider.SetStateInfo(newState);
}

```

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

### Updating an existing state

```csharp

// Gets the state
StateInfo updateState = StateInfoProvider.GetStateInfo("NewState");
if (updateState != null)
{
    // Updates the state properties
    updateState.StateDisplayName = updateState.StateDisplayName.ToLower();

    // Saves the change to the database
    StateInfoProvider.SetStateInfo(updateState);
}

```

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

### Updating multiple states

```csharp

// Gets the parent country of the states
CountryInfo country = CountryInfoProvider.GetCountryInfo("NewCountry");
if (country != null)
{
    // Gets a collection of states within the parent country
    var states = StateInfoProvider.GetStates().WhereEquals("CountryID", country.CountryID);

    // Loops through individual states
    foreach (StateInfo state in states)
    {                       
        // Updates the state properties
        state.StateDisplayName = state.StateDisplayName.ToUpper();

        // Saves the change to the database
        StateInfoProvider.SetStateInfo(state);
    }
}

```

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

### Deleting a state

```csharp

// Gets the state
StateInfo deleteState = StateInfoProvider.GetStateInfo("NewState");

if (deleteState != null)
{
    // Deletes the state
    StateInfoProvider.DeleteStateInfo(deleteState);
}

```

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