使用交换Web服务获取日历项目所需的参与者?C#

Sam*_*Sam 3 c# outlook add-in exchangewebservices

我正在尝试获得使用交换Web服务的会议所需的与会者.有任何想法吗?我想我需要使用CalendarItemType,但我不确定如何实现它.到目前为止,这是我的代码:

        foreach (var wrk in Workers)
        {
            TimeWindow timeWindow = new TimeWindow(startDate, endDate);
            AvailabilityData requestedData = AvailabilityData.FreeBusy;
            List<AttendeeInfo> attendees = new List<AttendeeInfo>();
            attendees.Add(new AttendeeInfo(wrk.EmailAddress));
            GetUserAvailabilityResults ares = service.GetUserAvailability(attendees, timeWindow, requestedData);
            foreach (AttendeeAvailability av in ares.AttendeesAvailability)
            {
                foreach (CalendarEvent ev in av.CalendarEvents)
                {
                    //get info from each calendarevent
                    //Possibly use CalendarItemType here?
                 }
             }
         }
Run Code Online (Sandbox Code Playgroud)

工人是我用类名单和相应的电子邮件地址列出的类.

Jak*_*sen 6

您可以使用Appointment.Bind以下方式绑定到约会来检索所需的与会者:

foreach (CalendarEvent ev in av.CalendarEvents)
{
    var appointment = Appointment.Bind(service, new ItemId(ev.Details.StoreId));
    foreach (var requiredAttendee in appointment.RequiredAttendees)
    {
        Console.WriteLine(requiredAttendee.Address);
    }
}
Run Code Online (Sandbox Code Playgroud)

您可能必须CalendarEvent.Details.StoreId在调用之前转换为其他格式Appointment.Bind(我不确定),所以如果上述代码不起作用,您可以尝试添加一个调用ExchangeService.ConvertId:

foreach (CalendarEvent ev in av.CalendarEvents)
{
    var convertedId = (AlternateId) service.ConvertId(new AlternateId(IdFormat.HexEntryId, ev.Details.StoreId, "someemail@domain.com"), IdFormat.EwsId);

    var appointment = Appointment.Bind(service, new ItemId(convertedId.UniqueId));
    foreach (var requiredAttendee in appointment.RequiredAttendees)
    {
        Console.WriteLine(requiredAttendee.Address);
    }
}
Run Code Online (Sandbox Code Playgroud)