我想使用 Microsoft Graph 创建一个日历事件,这很有效,但不幸的是,我无法向该事件添加附件。事件已创建,但没有附件。没有错误报告。
这是我的代码:
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);