rianjs / ical.net

ical.NET - an open source iCal library for .NET
MIT License
782 stars 230 forks source link

How to add VAlarm? #500

Open budbachman opened 4 years ago

budbachman commented 4 years ago

I'm not seeing how to add the VALARM to the Event. The Alarms mechanism is used to read Alarms, not set them. I created the Alarm and created the event. So, how do I get the Alarm to show up within the event? Here is my code so far:

        var myAlarm = new Alarm
        {
            Duration = TimeSpan.FromMinutes(-15),
            Action = "DISPLAY",
            Description = "Reminder"
        };

        var calendar = new Calendar();

        calendar.Events.Add(new CalendarEvent
        {
            Start = new CalDateTime(newapptSchedule.AppointmentDateTime.ToUniversalTime()),
            End = new CalDateTime(endTime.ToUniversalTime()),
            Description = "This is my test",
            Summary = "Phone Call",
            Location = newapptSchedule.PhoneNumber
        });

How do I move forward?

George221b commented 3 years ago

Hello there,

I will answer your question a bit late but hopes it helps you or someone else. I've added alarms successfully in the following way:

Alarm reminder = new Alarm
{
    Summary = title,
    Action = AlarmAction.Display,
    Trigger = new Trigger(TimeSpan.FromHours(-15)), // 9 AM the day before              
};

var e = new CalendarEvent
{
    Description = description,
    Summary = title,
    Uid = $"test",
    Start = new CalDateTime(date.Value),
    IsAllDay = true,
    Alarms = { reminder }
};

With that code I've set an alarm for 9 AM the day before the event. If you want an alarm for 30 minutes before the event use TimeSpan.FromMinutes(-30).

Hope that helps.