---
title: Polls
---

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

## Polls

### Creating a poll

```csharp

// Creates a new poll object
PollInfo newPoll = new PollInfo();

// Sets the poll properties (the poll is global)
newPoll.PollDisplayName = "Color poll";
newPoll.PollCodeName = "ColorPoll";
newPoll.PollTitle = "Color poll";
newPoll.PollQuestion = "What is your favorite color?";
newPoll.PollResponseMessage = "Thank you for voting.";
newPoll.PollAllowMultipleAnswers = false;
newPoll.PollAccess = SecurityAccessEnum.AllUsers;

// Saves the new poll to the database
PollInfoProvider.SetPollInfo(newPoll);

```

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

### Updating a poll

```csharp

// Gets the poll
// In this case, the poll is global. The . prefix in the code name parameter specifies a global poll.
PollInfo updatePoll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (updatePoll != null)
{
    // Updates the poll properties
    updatePoll.PollDisplayName = updatePoll.PollDisplayName.ToLower();

    // Saves the updated poll to the database
    PollInfoProvider.SetPollInfo(updatePoll);
}

```

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

### Updating multiple polls

```csharp

// Gets all polls created for the current site
// Only returns polls created directly for the given site. Does not include global polls that are made available on the site.
InfoDataSet<PollInfo> polls = PollInfoProvider.GetPolls(SiteContext.CurrentSiteID);

// Loops through individual polls
foreach (PollInfo poll in polls)
{
    // Updates the poll properties
    poll.PollDisplayName = poll.PollDisplayName.ToUpper();

    // Saves the updated poll to the database
    PollInfoProvider.SetPollInfo(poll);
}

```

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

### Making a global poll available on a site

```csharp

// Gets the global poll. The . prefix in the code name parameter specifies a global poll.
PollInfo poll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (poll != null)
{
    // Assigns the global poll to the current site
    PollSiteInfoProvider.AddPollToSite(poll.PollID, SiteContext.CurrentSiteID);
}

```

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

### Removing a global poll from a site

```csharp

// Gets the global poll. The . prefix in the code name parameter specifies a global poll.
PollInfo poll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (poll != null)
{
    // Removes the global poll from the current site
    PollSiteInfoProvider.RemovePollFromSite(poll.PollID, SiteContext.CurrentSiteID);
}

```

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

### Deleting a poll

```csharp

// Gets the poll
// In this case, the poll is global. The . prefix in the code name parameter specifies a global poll.
PollInfo deletePoll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (deletePoll != null)
{
    // Deletes the poll
    PollInfoProvider.DeletePollInfo(deletePoll);
}

```

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

## Poll answers

### Adding answers to a poll

```csharp

// Gets the poll
// In this case, the poll is global. The . prefix in the code name parameter specifies a global poll.
PollInfo poll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (poll != null)
{
    // Creates a new answer object
    PollAnswerInfo newAnswer = new PollAnswerInfo();

    // Sets the answer properties and assigns the answer to the specified poll
    newAnswer.AnswerPollID = poll.PollID;
    newAnswer.AnswerText = "My favorite color is blue.";
    newAnswer.AnswerEnabled = true;
    newAnswer.AnswerCount = 0;

    // Saves the poll answer to the database
    PollAnswerInfoProvider.SetPollAnswerInfo(newAnswer);
}

```

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

### Updating poll answers

```csharp

// Gets the poll
// In this case, the poll is global. The . prefix in the code name parameter specifies a global poll.
PollInfo poll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (poll != null)
{
    // Gets the poll's answers
    InfoDataSet<PollAnswerInfo> answers = PollAnswerInfoProvider.GetAnswers(poll.PollID);

    // Loops through individual poll answers
    foreach (PollAnswerInfo answer in answers)
    {
        // Updates the answer properties
        answer.AnswerText = answer.AnswerText.ToUpper();

        // Saves the updated poll answer to the database
        PollAnswerInfoProvider.SetPollAnswerInfo(answer);
    }
}

```

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

### Deleting poll answers

```csharp

// Gets the poll
// In this case, the poll is global. The . prefix in the code name parameter specifies a global poll.
PollInfo poll = PollInfoProvider.GetPollInfo(".ColorPoll", 0);

if (poll != null)
{
    // Gets the poll's first answer
    InfoDataSet<PollAnswerInfo> answers = PollAnswerInfoProvider.GetAnswers(poll.PollID, 1, null);
    PollAnswerInfo deleteAnswer = (PollAnswerInfo)answers.Items.FirstItem;

    if (deleteAnswer != null)
    {                   
        // Deletes the poll answer
        PollAnswerInfoProvider.DeletePollAnswerInfo(deleteAnswer);
    }
}

```

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