使用GraphServiceClient创建事件时无法添加附件

时间:2020-06-03 10:36:09

标签: c#-4.0 microsoft-graph-api

我正在尝试使用GraphServiceClient的事件创建与附件开会的在线团队。如果我不提供附件,则可以创建在线会议,但是在提供附件时出现错误提示。

ServiceException: 
Code: ErrorAttachmentsNotSupported
Message: Attachments are not supported.
Inner error:
    AdditionalData:
    request-id: cb69967c-3c63-4b04-b232-333d540a51c6
    date: 2020-06-03T10:14:42
ClientRequestId: cb69967c-3c63-4b04-b232-333d540a51c6  

下面是代码

        string OrgnizerUserIdTemp = "userid";

        var aAttachments = new EventAttachmentsCollectionPage();
        byte[] contentbytes = System.IO.File.ReadAllBytes(@"C:\temp\test.pdf");

        aAttachments.Add(new FileAttachment
        {
            Name = "Test.pdf",
            ContentBytes = contentbytes,
            ContentType = "application/pdf",
            ODataType = "#microsoft.graph.fileAttachment",
            Size = contentbytes.Length
        });

        var @event = new Event
        {
            Subject = "Online Meeting for Teams",
            Body = new ItemBody
            {
                ContentType = BodyType.Html,
                Content = "Some body content text here?<BR /> <B>Some Bold Text </B>"
            },
            Start = new DateTimeTimeZone
            {
                DateTime = "2020-06-03T12:00:00",
                TimeZone = "Europe/London"
            },
            End = new DateTimeTimeZone
            {
                DateTime = "2020-06-03T14:00:00",
                TimeZone = "Europe/London"
            },
            Location = new Location
            {
                DisplayName = "Lunch by Heston Blumenthal"
            },
            Attendees = new List<Attendee>()
            {
                new Attendee
                {
                    EmailAddress = new EmailAddress
                    {
                        Address = "AdeleV@sanjayksaxena.onmicrosoft.com",
                        Name = "Adele Vance"
                    },
                    Type = AttendeeType.Required
                },
                new Attendee
                {
                    EmailAddress = new EmailAddress
                    {
                        Address = "sanjay.saxena@sanjayksaxena.onmicrosoft.com",
                        Name = "Sanjay Saxena"
                    },
                    Type = AttendeeType.Required
                },
                new Attendee
                {
                    EmailAddress = new EmailAddress
                    {
                        Address = "user2@gmail.com",
                        Name = "User 2"
                    },
                    Type = AttendeeType.Optional
                }
            },
            IsOnlineMeeting = true,
            AllowNewTimeProposals = true,
            TransactionId = "7E163156-7762-4BEB-A1C6-729EA81755A1",
            Attachments = aAttachments, 
            HasAttachments = true
        };

        var om = graphServiceClient.Users[OrgnizerUserIdTemp].Events
            .Request()
            .Header("Prefer", "outlook.timezone=\"Europe/London\"")
            .AddAsync(@event).Result;

是否可以将附件添加到事件中? 要么 是否还有其他方法可以创建带有附件的Teams在线会议。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

onlineMeeting resource type不支持添加附件。 但是您可以创建带有附件的日历事件,它有一些限制。 请在下面找到有关如何向日历事件here添加附件的链接。

日历附件的限制: 您只能将附件对象添加到用户日历中的事件,而不能添加到组日历中的事件。