Outlook 集成 - 约会发送事件
Outlook integration - Appointment send event
我对 Outlook 库的 AppointmentItem 的 "Send" 事件有疑问。
每当我尝试为 "Send" 事件分配一些方法或操作时,就会抛出以下错误。有人可以向我解释或帮助我吗?
我知道必须有一个发送事件:https://msdn.microsoft.com/en-us/library/office/ff865990.aspx
这是我的代码:
private void btnOutlookCalendar_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
Outlook.Application outlookApp;
int collCount = processes.Length;
if (collCount != 0)
{
// Outlook already running, hook into the Outlook instance
outlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
}
else
{
outlookApp = new Microsoft.Office.Interop.Outlook.Application(); //neues Outlook Objekt erzeugen
}
Outlook.AppointmentItem oAppointment;
oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // neuen Kalendereintrag erstellen
oAppointment.Subject = this.dtoEvent.Bezeichnung; // set the subject
oAppointment.Body = "Automatisch durch das X erstelltes Event\n\n"
+ this.dtoEvent.Beschreibung + "\nWeitere Informationen:\n"
+ "X" + this.dtoEvent.ID;
oAppointment.Location = this.dtoEvent.Ort + ", " + this.dtoEvent.Strasse; // set the location
oAppointment.Start = Convert.ToDateTime(this.dtoEvent.Datum_Von + " " + this.dtoEvent.Uhrzeit_Von); // Set the start date
oAppointment.End = Convert.ToDateTime(this.dtoEvent.Datum_Bis + " " + this.dtoEvent.Uhrzeit_Bis); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
this.oAppointment = oAppointment;
oAppointment.Display(true);
oAppointment.Send += _appointment_Send;
}
private void _appointment_Send(ref bool Cancel)
{
if (MessageBox.Show("Wollen Sie die Veranstaltung per E-Mail verschicken?", "Frage", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
Outlook.MailItem mailItem = ((Outlook.AppointmentItem)oAppointment).ForwardAsVcal();
mailItem.Body = "X";
mailItem.Display();
}
}
如果您查看警告消息,您会看到以下内容:
Warning 1 Ambiguity between method 'Microsoft.Office.Interop.Outlook._MailItem.Send()' and non-method 'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Send'. Using method group.
因此,为避免此类错误或警告,您可以将邮件项目对象转换为 Microsoft.Office.Interop.Outlook.ItemEvents_10_Event 接口:
(mail as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += AddinModule_Send;
如果您想使用 Send
方法,您需要将项目对象转换为 _MailItem class。
我对 Outlook 库的 AppointmentItem 的 "Send" 事件有疑问。
每当我尝试为 "Send" 事件分配一些方法或操作时,就会抛出以下错误。有人可以向我解释或帮助我吗?
我知道必须有一个发送事件:https://msdn.microsoft.com/en-us/library/office/ff865990.aspx
这是我的代码:
private void btnOutlookCalendar_Click(object sender, RoutedEventArgs e)
{
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
Outlook.Application outlookApp;
int collCount = processes.Length;
if (collCount != 0)
{
// Outlook already running, hook into the Outlook instance
outlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
}
else
{
outlookApp = new Microsoft.Office.Interop.Outlook.Application(); //neues Outlook Objekt erzeugen
}
Outlook.AppointmentItem oAppointment;
oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // neuen Kalendereintrag erstellen
oAppointment.Subject = this.dtoEvent.Bezeichnung; // set the subject
oAppointment.Body = "Automatisch durch das X erstelltes Event\n\n"
+ this.dtoEvent.Beschreibung + "\nWeitere Informationen:\n"
+ "X" + this.dtoEvent.ID;
oAppointment.Location = this.dtoEvent.Ort + ", " + this.dtoEvent.Strasse; // set the location
oAppointment.Start = Convert.ToDateTime(this.dtoEvent.Datum_Von + " " + this.dtoEvent.Uhrzeit_Von); // Set the start date
oAppointment.End = Convert.ToDateTime(this.dtoEvent.Datum_Bis + " " + this.dtoEvent.Uhrzeit_Bis); // End date
oAppointment.ReminderSet = true; // Set the reminder
oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;
this.oAppointment = oAppointment;
oAppointment.Display(true);
oAppointment.Send += _appointment_Send;
}
private void _appointment_Send(ref bool Cancel)
{
if (MessageBox.Show("Wollen Sie die Veranstaltung per E-Mail verschicken?", "Frage", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
Outlook.MailItem mailItem = ((Outlook.AppointmentItem)oAppointment).ForwardAsVcal();
mailItem.Body = "X";
mailItem.Display();
}
}
如果您查看警告消息,您会看到以下内容:
Warning 1 Ambiguity between method 'Microsoft.Office.Interop.Outlook._MailItem.Send()' and non-method 'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Send'. Using method group.
因此,为避免此类错误或警告,您可以将邮件项目对象转换为 Microsoft.Office.Interop.Outlook.ItemEvents_10_Event 接口:
(mail as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += AddinModule_Send;
如果您想使用 Send
方法,您需要将项目对象转换为 _MailItem class。