Search code examples
asp.net-mvc-4active-directoryoffice365azure-web-app-serviceoffice365api

Not able to Send calendar event Request with attachment O365-ASPNETMVC


I am trying to add attachment to calendar. As it requires event id I can't add using method AddCalendarEventAsync. So I'm trying to below code:\

var outlookServicesClient = await AuthenticationHelper.EnsureOutlookServicesClientCreatedAsync("Calendar");
                             await outlookServicesClient.Me.Calendar.Events.AddEventAsync(newEvent);
                var thisEventFetcher = outlookServicesClient.Me.Calendar.Events.GetById(newEvent.Id);               
                await thisEventFetcher.Attachments.AddAttachmentAsync(attachments[0]);

File is Attached to calendar event when i open 365 office calendar, but To Recipients didn't get any attachment.The problem is First event created after based on Id add the Attachment, so before executing AddAttachmentAsync method mails are send to Recipients.

Ref link https://github.com/OfficeDev/O365-ASPNETMVC-Start

Can you please suggest me how to handle this issue.

Thanks, Hemanth.


Solution

  • After the organizer adding the attachments, it is need to update the event. For example, we can change the body of event like below:

        await thisEventFetcher.Attachments.AddAttachmentAsync(fileAttach);
            IEvent eventToUpdate =await thisEventFetcher.ExecuteAsync();
    
            ItemBody newBody = new ItemBody
            {
                Content = "Status updates, blocking issues, and next steps.(Update)",
                ContentType = BodyType.Text
            };
            eventToUpdate.Body=newBody;
    
            await eventToUpdate.UpdateAsync();