How to create a simple calendar event #603
-
Note: I am not sure if this is related to this issue, but when I generate a Calendar with an event, the Calendar contains no events. Using version 4.3.0 and .net 6.0. Code for generation:
What is begin generated:
the tag for event is missing from the generated content. If you try and import the .ics file into for example Outlook, it says that there are no events in the calendar. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Just double-checked with v4.2.0 to exclude your hint to this issue
Can you confirm? |
Beta Was this translation helpful? Give feedback.
-
@axunonb Yes, they look the same. It seems to be missing the BEGIN:VEVENT and END:VEVENT tags, as seen in the example here. |
Beta Was this translation helpful? Give feedback.
-
Here is the corrected code. var date = new CalDateTime(2024, 10, 15, 11, 0, 0);
var calendarEvent = new CalendarEvent
{
// If Name property is used, it MUST be RFC 5545 compliant
Summary = "Event Title", // Should always be present
Description = "Event description goes here", // optional
Start = new CalDateTime(date),
End = new CalDateTime(date.AddHours(2)),
};
var calendar = new Ical.Net.Calendar();
calendar.Events.Add(calendarEvent);
calendar.AddTimeZone(new VTimeZone("Europe/Copenhagen")); // TZ should be added
var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(calendar);
Console.WriteLine(serializedCalendar); Output (DTSTAMP and UID will differ):
|
Beta Was this translation helpful? Give feedback.
Here is the corrected code.
If you set the
CalendarEvent.Name
it MUST be RFC 5545 compliant.