ical-org / ical.net

ical.NET - an open source iCal library for .NET
MIT License
784 stars 231 forks source link

How do we update/remove attachments? #565

Closed aldrashan closed 17 hours ago

aldrashan commented 1 year ago

We're exporting a calendar event via EWS and importing it in a Ical.Net.Calendar object. This event already has attachments, but the data is missing (EWS doesn't export it, so that's normal). I want to update the existing attachments, but the Data property isn't settable nor is there any other method to update the contents. I also can't remove any attachments. If I were to clear the "ATTACH" group inside the Properties, the attachments are all gone, but then you can't add attachments anymore via the Attachments property. The wiki also doesn't tell us anything about this.

aldrashan commented 1 year ago

I've now tried copying the calendar object manually, leaving the attachments empty and re-adding them.

var newCalendar = new Ical.Net.Calendar();
var vEvent = new Ical.Net.CalendarComponents.CalendarEvent
{
    Attendees = calendarEvent.Attendees,
    ...
}
newCalendar.Events.Add(vEvent);
vEvent.Attachments = newAttachments;
var serializer = new CalendarSerializer();
var serializedCalendar = serializer.SerializeToString(newCalendar);

My attachment data only get serialized when you don't specify a URI. You can't combine byte[] data and an URI. The URI will take priority and your data won't get serialized. So how do we link attachments to their inline cid (i.e. name them and mark them as inline)?