Delete Ical event not working

3.1k views Asked by At

I am creating an ical event dynamically in my web application and when someone cancel the appointment on the application we are generating a delete ical event *.ics file to their email to remove the event in their calendar.

Creating is working perfectly but when we try to delete the appointment we created it doesn't remove it from the calendar

Creating Ical event code :

 string[] contents = { 
      "BEGIN:VCALENDAR",
      "VERSION:2.0",
      "PRODID:-//dev.com//iCal//EN",
      "X-WR-CALNAME:development",
      "X-WR-RELCALID:928C8448-048A-4aa2-BE27-A920773AF3DC",
      "X-FUNAMBOL-ALLDAY:0",
      "METHOD:REQUEST",
      "BEGIN:VEVENT",
      "UID:" + Args.EventUID, 
      "SEQUENCE:1",
      "DTSTART:" + Args.EventStartTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), 
      "DTEND:" +  Args.EventEndTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), 
      "LOCATION: " + Args.EventLocation, 
      "ORGANIZER: [email protected]",
      "DESCRIPTION;ENCODING=ESCAPED-CHAR:" + Args.EventName,
      "SUMMARY:" + Args.EventDescription, 
      "STATUS:CONFIRMED",
      "TRANSP:OPAQUE",
      "PRIORITY:" + Args.EventPriority.ToString(), 
      "END:VEVENT", 
      "END:VCALENDAR" 
 }; 

Creating an event works perfectly on iphone/android/outlook

Delete event part:

    string[] contents = { 
      "BEGIN:VCALENDAR",
      "VERSION:2.0",
      "METHOD:CANCEL",
      "X-WR-CALNAME:development",
      "X-WR-RELCALID:928C8448-048A-4aa2-BE27-A920773AF3DC",
      "PRODID:-//dev.com//iCal//EN",
      "X-FUNAMBOL-ALLDAY:0",
      "BEGIN:VEVENT",                                
      "UID:" + Args.EventUID,
      "SEQUENCE:2",
      "DTSTART:" + Args.EventStartTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), 
      "DTEND:" +  Args.EventEndTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"), 
      "LOCATION: " + Args.EventLocation, 
      "DESCRIPTION;ENCODING=ESCAPED-CHAR:" + Args.EventName,
      "SUMMARY:" + Args.EventDescription, 
      "ORGANIZER: [email protected]",
      "PRIORITY:" + Args.EventPriority.ToString(), 
      "STATUS:CANCELLED",
      "TRANSP:OPAQUE",
      "END:VEVENT", 
      "END:VCALENDAR" 
  };

When I click this file generated to remove the event that is already created it doesn't remove the event and sometimes it duplicates the event.

The ical UID on creating and delete are the same.

3

There are 3 answers

0
ingroxd On

Try using PUBLISH as METHOD and 0 as SEQUENCE for submitting and 1 as SEQUENCE for erasing.

Example of submitting:

string[] contents = {
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//site.domain//iCal//EN",
"METHOD:PUBLISH",
"BEGIN:VEVENT",
"UID:" + Args.EventUID,
"SEQUENCE:0",
"DTSTART:" + Args.EventStartTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
"DTEND:" +  Args.EventEndTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
"SUMMARY:" + Args.EventDescription,
"STATUS:CONFIRMED",
"END:VEVENT",
"END:VCALENDAR"
};

Example of erasing:

string[] contents = {
"BEGIN:VCALENDAR",
"VERSION:2.0",
"PRODID:-//site.domain//iCal//EN",
"METHOD:CANCEL",
"BEGIN:VEVENT",
"UID:" + Args.EventUID,
"SEQUENCE:1",
"DTSTART:" + Args.EventStartTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
"DTEND:" +  Args.EventEndTime.ToUniversalTime().ToString("yyyyMMdd\\THHmmss\\Z"),
"SUMMARY:" + Args.EventDescription,
"STATUS:CANCELLED",
"END:VEVENT",
"END:VCALENDAR"
};
0
bbsimonbb On

First, scrutinise the UID. I know you say they're the same, but check ! Whitespace? Case?

Next, put PRODID on the second line, straight after BEGIN (Ignore the validators when they tell you to put VERSION on the second line.) This sounds trivial, the field is not even used, but Outlook in particular is ridiculously picky. Copy a working example. Test and tell me if I'm wrong.

Next, SEQUENCE is indexed from 0. Clients may interpret SEQUENCE:1 as an update, and wonder where is the original invitation.

Next, check the structure and mime type headers of your emails. I got best results by sending a simple single part email with Content-type: text/calendar; method="[REQUEST/CANCEL]" in the MIME header.

Still not working? Try adding an ATTENDEE element, with participation required, rsvp true etc, repeating the email address of the recipient.

Still problems? Use the online Icalendar validators to check your output, but also copy exactly a working example. Send yourself an invitation, then cancel it, from gmail and/or outlook. Everything is important - the structure of the message, the order of the fields in the Icalendar, the MIME headers of the email. Sending to GMail lets you see exactly what is received, via the gmail show original option.

I notice you are doing nothing for wrapping. Ical lines are limited to 75 characters, not much, and overflowing lines must start with a space. A validator will quickly tell you.

0
anmari On

The difference may also be whether the calendar app has 'subscribed' or 'imported' the ics file? Subscribed events should update, imported ones generally may not as the user could have changed them - may vary between calendar apps.