I want to create a calendar event using Microsoft Graph and this is working but unfortunately, I'm not able to add attachments to the event. The event is created but without the attachments. No error is reported.
This is my code:
DateTimeTimeZone start = new DateTimeTimeZone
{
TimeZone = TimeZoneInfo.Local.Id,
DateTime = dateTimePicker1.Value.ToString("o"),
};
DateTimeTimeZone end = new DateTimeTimeZone
{
TimeZone = TimeZoneInfo.Local.Id,
DateTime = dateTimePicker2.Value.ToString("o"),
};
Location location = new Location
{
DisplayName = "Thuis",
};
byte[] contentBytes = System.IO.File
.ReadAllBytes(@"C:\test\sample.pdf");
var ev = new Event();
FileAttachment fa = new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = "application/pdf",
Name = "sample.pdf",
IsInline = false,
Size = contentBytes.Length
};
ev.Attachments = new EventAttachmentsCollectionPage();
ev.Attachments.Add(fa);
ev.Start = start;
ev.End = end;
ev.IsAllDay = false;
ev.Location = location;
ev.Subject = textBox2.Text;
var response = await graphServiceClient
.Users["user@docned.nl"]
.Calendar
.Events
.Request()
.AddAsync(ev);