Create an all-day event using Native API
In order for an event to be treated as an all-day event by Sitefinity CMS, it must comply with the following:
- The start time must be set to 12:00:00 am.
- The end time must be set to 12:00:00 am.
- The start and end date should be created in UTC format.
- The event’s
AllDayEventproperty must be set totrue
The following code creates an all-day event that lasts only one day with specified ID, Title, Content, StartDate, EndDate through the Native API:
C#
using System;
using Telerik.Sitefinity.Modules.Events;
using Telerik.Sitefinity.Events.Model;
namespace SitefinityWebApp
{
public partial class EventSnippets
{
public void CreateAllDayEvent()
{
EventsManager manager = EventsManager.GetManager();
var eventTitle = "Title normal all day event-1";
var eventContent = "Content normal allDay event-";
DateTime eventStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, DateTimeKind.Utc);
DateTime eventEnd = eventStart.AddDays(1);
string timezoneId = TimeZoneInfo.Utc.Id;
Guid eventGuid = Guid.NewGuid();
Event allDayEvent = manager.CreateEvent(eventGuid);
allDayEvent.Title = eventTitle;
allDayEvent.Content = eventContent;
allDayEvent.EventStart = eventStart;
allDayEvent.EventEnd = eventEnd;
allDayEvent.AllDayEvent = true;
allDayEvent.TimeZoneId = timezoneId;
allDayEvent.ApprovalWorkflowState = "Published";
manager.Lifecycle.Publish(allDayEvent);
manager.SaveChanges();
}
}
}
Want to learn more?
Enhance your Sitefinity skills by enrolling in free training sessions. Become Sitefinity certified through Progress Education Community to strengthen your professional credentials.
Get started with Integration Hub | Sitefinity Cloud
This free lesson teaches administrators, marketers, and other business professionals how to use Sitefinity Integration Hub to create automated workflows between Sitefinity and other business systems.
Web Security for Sitefinity Administrators
This free lesson teaches administrators the basics about protecting your Sitefinity instance and your 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 ASP.NET Core and take advantage of its decoupled architecture and modern development model.