![](/img/trans.png)
[英]Create Appointment in my secondary outlook calendar (Ews managed API)
[英]Delete a calendar appointment from all users with EWS Managed API
我有一个在Office Online 365的Exchange Online中的日历中创建约会的应用程序。我正在使用EWS托管API。
public void CreateAppoitment(string principalName, int taskId) {
ExchangeService service = createService(principalName);
ItemView itemView = new ItemView(1000);
itemView.PropertySet = new PropertySet(BasePropertySet.IdOnly);
List<Appointment> toCreate = new List<Appointment>();
// Create the appointment.
Appointment appointment = new Appointment(service);
// Set properties on the appointment.
appointment.Subject = "Test Appointment";
appointment.Body = "The appointment ...";
appointment.Start = new DateTime(2014, 6, 18, 9, 0, 0);
appointment.End = appointment.Start.AddDays(2);
ExtendedPropertyDefinition epdTaskId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Appointment, "TASK_Id", MapiPropertyType.Integer);
appointment.SetExtendedProperty(epdTaskId, taskId);
appointment.IsResponseRequested = false;
toCreate.Add(appointment);
ServiceResponseCollection<ServiceResponse> createResponse = service.CreateItems(toCreate, WellKnownFolderName.Calendar, MessageDisposition.SaveOnly, SendInvitationsMode.SendToNone);
}
注意我正在设置ExtendedPropertyDefinition“ TASK_Id”
我正在使用模拟在用户的日历中创建约会:
private ExchangeService createService(string principalName) {
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
service.UseDefaultCredentials = false;
service.Credentials = new WebCredentials("XXXX", "YYYY");
service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, principalName);
return service;
}
然后,给定一个taskId,我想删除所有与此taskId相关的约会:
public void DeleteAppointment(string principalName, int appointmentId) {
ExchangeService service = createService(principalName);
ItemView itemView = new ItemView(1000);
itemView.PropertySet = new PropertySet(BasePropertySet.IdOnly);
ExtendedPropertyDefinition epdTaskId = new ExtendedPropertyDefinition(
DefaultExtendedPropertySet.Appointment, "TASK_Id", MapiPropertyType.Integer);
SearchFilter filterOnTaskId = new SearchFilter.IsEqualTo(epdTaskId, appointmentId);
FindItemsResults<Item> appointments = service.FindItems(WellKnownFolderName.Calendar, filterOnTaskId, itemView);
List<ItemId> toDelete = appointments.Select(item => item.Id).ToList();
if (toDelete.Count > 0) {
ServiceResponseCollection<ServiceResponse> response = service.DeleteItems(
toDelete, DeleteMode.MoveToDeletedItems, SendCancellationsMode.SendToNone,
AffectedTaskOccurrence.SpecifiedOccurrenceOnly);
foreach (ServiceResponse del in response) {
if (del.Result == ServiceResult.Error) {
//...
}
}
}
}
但是这种方式service.FindItems()仅返回TASK_Id = taskId的principalName的约会,并且我希望所有用户的约会。 有没有办法做到这一点?
Exchange托管API和Exchange Web服务一次仅提供对一个用户日历的访问权限-可以直接使用用户的凭据直接访问,也可以使用模拟间接地授予服务帐户访问用户日历的访问权限。
一次搜索多个日历需要不同的技术。 想到的一种选择是使用Exchange 2013中的eDiscovery操作。尽管出于法律原因通常将它们用于查找电子邮件,但您也可以使用相同的过程。 不幸的是,eDiscovery的文档目前非常稀疏,但是您可以在此处查看可用的EWS操作: Exchange中EWS中的eDiscovery ,并且可以在ExchangeService对象上找到相应的EWS托管API方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.