0

I use ICAL .NET to create a webcalendar link in my ASP .NET Core application. My service code is inspired from this post :

        [AllowAnonymous]
        [HttpGet("ical/{icalSecret:Guid}")]
        public IActionResult GetICalFeed(Guid icalSecret)
        {

            var calendar = this.eventService.GetUserCalendar(icalSecret);
            var serializer = new CalendarSerializer();
            var serializedCalendar = serializer.SerializeToString(calendar);
            var contentType = "text/calendar";
            var bytes = Encoding.UTF8.GetBytes(serializedCalendar);

            return File(bytes, contentType, "calendar.ics");
        }

And the method that generates the calendar :

        public Calendar GetUserCalendar(Guid icalSecret)
        {
            var user = this._userRepository.GetByICalSecret(icalSecret);
            var events = this._eventRepository.GetUserFutureEvents(user.Id);

             var calendarEvents = events.Select(evt => new CalendarEvent()
             {
                 Start = new CalDateTime(evt.Start),
                 End = new CalDateTime(evt.End),
                 Attendees = evt.Participations.Select(p => new Attendee(){CommonName = p.User.Username, Value = new Uri($"mailto:{p.User.Email}")}).ToList(),
                 Description = evt.Description
             });

             var calendar = new Calendar();
             foreach (var calendarEvent in calendarEvents)
             {
                 calendar.Events.Add(calendarEvent);
             }

             return calendar;
        }

And the returned ical fil seems fine to me :

BEGIN:VCALENDAR
PRODID:-//github.com/rianjs/ical.net//NONSGML ical.net 4.0//EN
VERSION:2.0
BEGIN:STRING
ATTENDEE;CN=test mail:mailto:test@test.fr
ATTENDEE;CN=test droits:mailto:test@test.fr
ATTENDEE;CN=jm:mailto:test@test.com
ATTENDEE;CN=test:mailto:test@test.fr
DESCRIPTION:string
DTEND:20200610T093036
DTSTAMP:20200602T093344Z
DTSTART:20200610T093036
SEQUENCE:0
UID:a8845fea-6d16-49df-aa5e-a8cf61e1575a
END:STRING
END:VCALENDAR

But windows calendar app can't open it (says it's damaged) and it fails validation on this ICAL validator.

Do you have any clue of what I did wrong?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Ombrelin
  • 547
  • 1
  • 8
  • 27

1 Answers1

1

Ok turn out I used the wrong field to store the name of my event in ICAL.NET. One should use the field Summary and not the field Name.

Ombrelin
  • 547
  • 1
  • 8
  • 27