0

I am using https://github.com/rianjs/ical.net with .Net 6 API. I am able to create an event like below.

            var calendar = new Calendar();
            calendar.AddTimeZone(new VTimeZone("America/Chicago"));
            var icalEvent = new CalendarEvent
            {
                Summary = "David's vacation days",
                Description = "Description for event",
                Start = new CalDateTime(2022, 12, 12, 15, 0, 0),
                End = new CalDateTime(2022, 12, 12, 16, 0, 0)
            };
            calendar.Events.Add(icalEvent);

            var iCalSerializer = new CalendarSerializer();
            result = iCalSerializer.SerializeToString(calendar);

This creates a .ics file, opening which creates an event in the calendar.

BEGIN:VCALENDAR PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN VERSION:2.0 BEGIN:VTIMEZONE TZID:America/Chicago X-LIC-LOCATION:America/Chicago END:VTIMEZONE BEGIN:VEVENT DESCRIPTION:Description for event DTEND:20221212T160000 DTSTAMP:20221213T184639Z DTSTART:20221212T150000 SEQUENCE:0 SUMMARY:David's vacation days UID:4aca19e6-a7a8-426c-a488-c2abf789c395 END:VEVENT END:VCALENDAR

I see that if I edit the file and add METHOD:CANCEL, SEQUENCE:1, it opens in outlook with 'Remove from calendar'.

Now, how to do this remove event programmatically? I am hoping iCAL has something instead of me serializing the event to string and add the method etc. to that string manually.

Jap Evans
  • 1,097
  • 8
  • 22
  • 42
  • Are you looking to remove events based on whether they are cancelled? – Slava Knyazev Dec 13 '22 at 20:14
  • I create an email based on some approval process. In that email, I give the users 'Add to calendar' link to add an event via an ics file. If the approval is later rejected, I want to remove the event from calendar through a 'Remove from calendar' link that opens an ics file. – Jap Evans Dec 13 '22 at 21:01
  • I'm not an ical expert, but I suspect that "Remove from Calendar" is an outlook thing. There is no such thing in ical as a "Removed" status, only "Cancelled" which the client can then remove at their own discretion. – Slava Knyazev Dec 13 '22 at 21:07
  • I was able to make it remove from calendar. But I manually edited the ics file. It must have same Uid, sequence greater than what was in create ics file. And status should be CANCELLED and method as CANCEL. When you open this ics file, it prompts with outlook window that says 'Remove from calendar' – Jap Evans Dec 14 '22 at 15:12
  • My question is how to do this programmatically using iCAL.Net – Jap Evans Dec 14 '22 at 15:12
  • So you just want to update the status to cancelled? – Slava Knyazev Dec 14 '22 at 17:43

0 Answers0