2016-12-13 35 views
0

我遇到了Outlook库的AppointmentItem的“发送”事件问题。Outlook集成 - 约会发送事件

每当我尝试将某些方法或动作分配给“发送”事件时,会引发以下错误。有人可以向我解释或帮助我吗?

我知道必须有一个发送事件:https://msdn.microsoft.com/en-us/library/office/ff865990.aspx

error in Visual Studio

这是我的代码:

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(); 


     } 
    } 

回答

1

如果你看一看,你可以看到下面的警告消息:

警告1方法'Microsoft.Office.Interop之间的歧义.Outlook._MailItem.Send()'和非方法'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Send'。使用方法组。

因此,为了避免这样的错误或警告,就可以把邮件项目对象为Microsoft.Office.Interop.Outlook.ItemEvents_10_Event接口:

(mail as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += AddinModule_Send; 

如果你想使用Send方法,你需要将项目目标投射到改为_MailItem

+0

非常感谢您的帮助!这工作!但不幸的是,我现在有另一个问题。如果我连接“AfterWrite”事件并尝试将保存的约会作为附件发送,我的程序就会崩溃。 (请参阅_appointment_send()方法)。问题是,即使在“AfterWrite”事件触发后,预约的Outlook窗口仍然打开,由于这个原因,我认为我无法访问保存的预约。 – Maximus1809