繁体   English   中英

Exchange EWS获取房间日历

[英]Exchange EWS Get calendar for room

我正在尝试为特定会议室召开所有会议,也许我走错了路,但到目前为止,当我模拟会议室并获得日历视图时,最有希望的结果是产生的-问题是每个会议室日历条目, 主题包含用户名,而不是实际的会议主题。 例如,不是包含“预算会议”的主题数据成员,而是包含“鲍勃·史密斯”。

是否有更好的方法来获取特定房间的日历条目列表? 这是我的代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("bobsled@yourdomain.onmicrosoft.com", "password");
service.AutodiscoverUrl("bobsmith@yourdomain.com", RedirectionUrlValidationCallback);
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "sanfrancisco@yourdomain.onmicrosoft.com");

DateTime startDate = DateTime.Now;
DateTime endDate = startDate.AddDays(30);
const int NUM_APPTS = 5;

CalendarFolder calendar = CalendarFolder.Bind(service, WellKnownFolderName.Calendar, new PropertySet());
CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);

foreach (Appointment a in appointments)
{
    Console.Write("Subject: " + a.Subject.ToString() + " ");
    Console.Write("Start: " + a.Start.ToString() + " ");
    Console.Write("End: " + a.End.ToString());
    Console.WriteLine();
}

如果您想尝试另一种方法,则可以获取所有约会,然后按位置进行过滤:

ExchangeServices.ExchangeService exchangeService = connectToServiceWhatever(userInfo); // have working service
var folderView = new ExchangeServices.FolderView(100);   // or something like 100, idunno
folderView.Traversal = ExchangeServices.FolderTraversal.Deep;
folderView.PropertySet = new ExchangeServices.PropertySet(ExchangeServices.FolderSchema.FolderClass,
                ExchangeServices.FolderSchema.DisplayName, ExchangeServices.FolderSchema.TotalCount,
                ExchangeServices.FolderSchema.ParentFolderId);   // ... and/or whatever else you want to get - folderclass is important though. 
ExchangeServices.FindFoldersResults folders = exchangeService.FindFolders(ExchangeServices.WellKnownFolderName.MsgFolderRoot, folderView);

现在,您需要做的是根据文件夹类型进行筛选,获取所有项目,然后根据房间进行筛选:

var appointments = folders.Where(f => f.FolderClass == "IPF.Appointment").SelectMany(f => exchangeService.FindItems(f.Id, new ExchangeServices.ItemView(folder.TotalCount < 5 ? folder.TotalCount : 5)).Where(a => a.Location == "Boardroom");  // or whatever room you want. 

这可能不是复制可粘贴的,因为我现在刚刚将其键入,但是我希望它足以使想法得到传播。 您最终需要做更多的工作,但希望您最终还可以检查约会。主题,约会.Start | End.ToUniversalTime()等。

这是工作代码:

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
service.Credentials = new WebCredentials("bobsmith@yourdomain.onmicrosoft.com", "password");
service.AutodiscoverUrl("bobsmith@yourdomain.onmicrosoft.com", RedirectionUrlValidationCallback);

var folderView = new FolderView(100);   // or something like 100, idunno
folderView.Traversal = FolderTraversal.Deep;
folderView.PropertySet = new PropertySet(FolderSchema.FolderClass,FolderSchema.DisplayName, FolderSchema.TotalCount,FolderSchema.ParentFolderId);   // ... and/or whatever else you want to get - folderclass is important though. 

FindFoldersResults folders = service.FindFolders(WellKnownFolderName.MsgFolderRoot, folderView);
// Process each item.
foreach (Folder myFolder in folders.Folders)
{
    if (myFolder is CalendarFolder)
    {
        var calendar = (myFolder as CalendarFolder);
        // Initialize values for the start and end times, and the number of appointments to retrieve.
        DateTime startDate = DateTime.Now;
        DateTime endDate = startDate.AddDays(30);
        const int NUM_APPTS = 15;
        // Set the start and end time and number of appointments to retrieve.
        CalendarView cView = new CalendarView(startDate, endDate, NUM_APPTS);
        // Limit the properties returned to the appointment's subject, start time, and end time.
        cView.PropertySet = new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End);
        // Retrieve a collection of appointments by using the calendar view.
        FindItemsResults<Appointment> appointments = calendar.FindAppointments(cView);
        foreach (Appointment a in appointments)
        {
            Console.Write("Subject: " + a.Subject.ToString() + " ");
            Console.Write("Start: " + a.Start.ToString() + " ");
            Console.Write("End: " + a.End.ToString());
            Console.WriteLine();
        }
    }
}

默认情况下,在将约会发送到会议室资源时,Exchange用组织者的名称替换主题。 可以使用以下命令通过Exchange管理控制台将其禁用,以保留主题

Set-CalendarProcessing -Identity <RESOURCEMAILBOX> -DeleteSubject $False -AddOrganizerToSubject $False

参考: https : //support.microsoft.com/zh-cn/help/2842288/resource-mailbox-s-calendar-shows-the-organizer-s-name-instead-of-the

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM