Create a recurrent all-day event with a specific timezone ID

NEW TO SITEFINITY?

Use the following code sample to create a recurrent all-day event with specific timezone ID:

using System;
using Telerik.Sitefinity.Events.Model;
using Telerik.Sitefinity.Modules.Events;
using Telerik.Sitefinity.RecurrentRules;
namespace SitefinityWebApp
{
public class CreateAllDayRecurrentEvents
{
public static void CreateRecurrentAllDayEvent()
{
/// Creates a date in UTC (Coordinated Universal Time) format
var startDate = new DateTime(2015, 11, 1, 0, 0, 0, DateTimeKind.Utc);
/// Creates end date which is 10 days after the start event date.
var endDate = startDate.AddDays(10);
///Gets an instance of the events manager.
EventsManager manager = EventsManager.GetManager();
Guid id = Guid.NewGuid();
/// Set timezone id.
string utcTimezoneId = "UTC";
/// Creates a new event with the given identity
Event recurrentEvent = manager.CreateEvent(id);
///Set Title (name) of the content item
recurrentEvent.Title = "Recurrent all day event";
///Sets the description of this content.
recurrentEvent.Description = "Recurrent all day event description";
///Sets the event content
recurrentEvent.Content = "Recurrent all day event content";
///Sets the start date/time of the event in UTC.
recurrentEvent.EventStart = startDate;
///Sets the end date/time of the event in UTC.
recurrentEvent.EventEnd = endDate;
///Sets whether the event contains any recurrence logic.
recurrentEvent.IsRecurrent = true;
///Sets whether the event is all day event.
recurrentEvent.AllDayEvent = true;
///Sets the location of the current event.
recurrentEvent.Location = "Recurrent all day event location";
///Sets the time zone id associated with the event
///This property is used for persisting the timezone chosen when creating an Event.
///The value of this property is important for recurrent events because it is
///used in recurrence expressions and DST as well.
///The TimeZoneId is a key string that uniquely identifies a particular time zone.
recurrentEvent.TimeZoneId = utcTimezoneId;
/// Defines methods for interacting/creating recurrence rules.
var rrBuilder = new RecurrenceRuleBuilder();
/// Creates an expression for a recurrent all day event with one day duration and 10 days occurrences.
var recurrentExpression = rrBuilder.CreateDailyRecurrenceExpression(startDate, TimeSpan.FromDays(1), endDate, 10, 1, utcTimezoneId);
///Sets the recurrence expression associated with the event.
recurrentEvent.RecurrenceExpression = recurrentExpression;
/// Publishes the defined event.
manager.Lifecycle.Publish(recurrentEvent);
/// Save the changes made to events retrieved with this manager.
manager.SaveChanges();
}
}
}

Want to learn more?

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?