Creating a new poll

The following sample code shows how you can create a new poll using the API:

 

[C#]

 

using CMS.Polls;

using CMS.SettingsProvider;

using CMS.CMSHelper;

using CMS.DataEngine;

using CMS.GlobalHelper;

 

...

 

       // Create new poll info

       PollInfo pollObj = new PollInfo();

 

       // Set the fields

       pollObj.PollCodeName = "testingsitepoll";

       pollObj.PollDisplayName = "Testing site poll";

       pollObj.PollTitle = "Your free time";

       pollObj.PollQuestion = "What do you do in your free time?";

       pollObj.PollResponseMessage = "Thank you for your vote.";

       pollObj.PollAllowMultipleAnswers = false;

       pollObj.PollAccess = PollInfoProvider.ACCESS_ALL;

       pollObj.PollOpenFrom = DateTime.Now;

       pollObj.PollOpenTo = DateTime.Now.AddMonths(1);

 

       // Save the object

       PollInfoProvider.SetPollInfo(pollObj);

 

       // Add poll to current site

       if (CMSContext.CurrentSite != null)

       {

           PollInfoProvider.AddPollToSite(pollObj.PollID, CMSContext.CurrentSite.SiteID);

       }