Office365 can';t向日历事件添加附件

Office365 can';t向日历事件添加附件,office365,office365api,Office365,Office365api,我正在尝试使用ASP.NET MVC的Office 365初学者项目向日历添加附件。因为它需要事件id,所以无法使用AddCalendarEventAsync方法添加。因此,我尝试使用以下代码更新事件: var outlookServicesClient = await AuthenticationHelper.EnsureOutlookServicesClientCreatedAsync("Calendar"); var thisEventFetcher = outlookServicesCl

我正在尝试使用ASP.NET MVC的Office 365初学者项目向日历添加附件。因为它需要事件id,所以无法使用AddCalendarEventAsync方法添加。因此,我尝试使用以下代码更新事件:

var outlookServicesClient = await AuthenticationHelper.EnsureOutlookServicesClientCreatedAsync("Calendar");
var thisEventFetcher = outlookServicesClient.Me.Calendar.Events.GetById(selectedEventId);
IEvent eventToUpdate = await thisEventFetcher.ExecuteAsync();
但“eventToUpdate”没有附件集属性。请检查一下,并说明如何在日历中添加附件


谢谢。

我使用outlookservicesclient将附件添加到事件中,但即使成功创建了事件,也找不到附件。outlookservicesclient似乎不包含附件数据。如果使用Fiddler,则无法在post请求中找到附件数据

您可以尝试使用Graph API向事件添加附件:

POST https://graph.microsoft.com/v1.0/me/messages/<id>/attachments
Content-type: application/json
Content-length: 142

{
   "@odata.type": "#microsoft.graph.fileAttachment",
   "name": "name-value",
   "contentBytes": "contentBytes-value"
}
POSThttps://graph.microsoft.com/v1.0/me/messages//attachments
内容类型:application/json
内容长度:142
{
“@odata.type”:“#microsoft.graph.fileAttachment”,
“名称”:“名称值”,
“contentBytes”:“contentBytes值”
}

请点击查看详细信息。

是@nan yu you's right在n fiddler中找不到附件数据。根据文档,它需要eventid来保存附件。所以我在“UpdateCalendarEventAsync”方法中使用代码。就像附件如何处理电子邮件一样,您可以将其另存为草稿并将附件添加到草稿中。下面的代码添加了附件,但当我使用eventid获取事件时,附件属性没有数据

Event newEvent = new Event
            {
             Subject = Subject,
                Location = location,
                Attendees = attendees,
                Start = start,
                End = end,
                Body = body
            };

            newEvent.Start = (DateTimeOffset?)CalcNewTime(newEvent.Start, start);
            newEvent.End = (DateTimeOffset?)CalcNewTime(newEvent.End, end);

            try
            {
                // Make sure we have a reference to the Outlook Services client
                var outlookServicesClient = await AuthenticationHelper.EnsureOutlookServicesClientCreatedAsync("Calendar");

                // This results in a call to the service.
                await outlookServicesClient.Me.Events.AddEventAsync(newEvent);
                newEventId = newEvent.Id;
                newEvent.Attachments = attachments;
                newEvent.HasAttachments = true;
                await ((IEventFetcher)newEvent).ExecuteAsync();
                await newEvent.UpdateAsync(true);
                var thisEventFetcher = outlookServicesClient.Me.Calendar.Events.GetById(newEventId);
                IEvent eventToUpdate = await thisEventFetcher.ExecuteAsync();
                await outlookServicesClient.Context.SaveChangesAsync();
            }

谢谢@nan yu..我无法使用outlookservicesclient添加附件。请您发布代码,用于使用outlookservicesclient向活动添加附件。这将非常好。然后我将首先在Fiddler中进行检查。例如,在CalendarOperations.cs中的AddCalendarEventAsync函数中。初始化newEvent后,添加附件:`FileAttachment ae=new FileAttachment();ae.ContentBytes=File.ReadAllBytes(@“D:\f.txt”);ae.Name=“text”;ae.Size=Convert.ToInt32(新文件信息(@“D:\f.txt”).Length);newEvent.Attachments.Add(ae);`然后你可以用Fiddlerp查看帖子请求,请看我对上面这篇帖子的回答。
var thisEventFetcher = outlookServicesClient.Me.Calendar.Events.GetById(eventID);
Attachment attachment = new FileAttachment
                                {
                                    Name = "test",
                                    ContentBytes = File.ReadAllBytes(@"D:\test.jpeg"),
                                    ContentType = "image/jpeg"
                                };
                                await thisEventFetcher.Attachments.AddAttachmentAsync(attachment);