2016-06-01 5 views
2

Ich möchte eine Besprechungsanfrage an somebodies senden (Mails in einer Liste). Das Meeting kann nicht im Standardkalender enthalten sein. Es muss in der (fullpathCalendar)"\\Methode\Calendar" sein.C# Hinzufügen einer Besprechungsanfrage in einem anderen Kalender, der standardmäßig

Dies ist, was ich bisher:

Outlook.Application OutlookApp = new Outlook.Application(); 
// Change the session or calendar ? 
Outlook.AppointmentItem appt = (Outlook.AppointmentItem) 
     OutlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); 

appt.Subject = ""; 
appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; 
appt.Location = ""; 
appt.Start = DateTime.Now.AddHours(2); 
appt.End = DateTime.Now.AddHours(3); 
appt.AllDayEvent = false; 
appt.Body = "sdfsdfsdfdsfsfdsfdsfsfsfdsfsfsdfsd"; 

Wie kann ich den Termin in diesem Kalender zuweisen?

+0

könnte so etwas wie 'var Kalender = OutlookApp.GetFolderPath ("path \ Kalendername") sein' und dann 'appt.Move (Kalender)'? – stuartd

+0

Warum habe ich das überhaupt gesehen? Es funktioniert perfekt. Danke @stuartd – Monstreur

+0

Weißt du, wie man die eingeladenen dazu bringt, das Treffen zu akzeptieren? – Monstreur

Antwort

0

Für jemand das gleiche wollen:

 string sendText = ""; 
     string subject = ""; 
     string location = ""; 
     string emails = {"[email protected]", "[email protected]"}; 
     Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application(); 
     Outlook.AppointmentItem appt = (Outlook.AppointmentItem)app.CreateItem(Outlook.OlItemType.olAppointmentItem); 

     appt.Subject = subject; 
     appt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting; 
     appt.Location = location; 
     appt.Start = DateTime.Now.AddHours(1); 
     appt.End = DateTime.Now.AddHours(3); 
     appt.AllDayEvent = false; 
     appt.Body = sendText; 
     appt.ResponseRequested = false; 

     foreach (string email in emails) 
     { 
      Outlook.Recipient recipRequired = appt.Recipients.Add(email); 
      recipRequired.Type = (int)Outlook.OlMeetingRecipientType.olRequired; 
     } 

     appt.Recipients.ResolveAll(); 
     appt.Display(true); 

     try 
     { 
      Outlook.MAPIFolder calendar = Data.OutlookHelper.AdxCalendar.getCallendar(app, @"\\Fichier de données Outlook\Calendrier\Methode"); 
      appt.Move(calendar); 
     } 
     catch 
     { 
      Dialogs.Alert alert = new Dialogs.Alert("Erreur", "Le rendez-vous est introuvable, vous l'avez peut-être supprimer."); 
      alert.ShowDialog(); 
     } 

Und mein Data.OutlookHelper.AdxCalendar:

using System; 
using System.Collections.Generic; 
using System.Diagnostics; 
using System.Reflection; 
using System.Runtime.InteropServices; 
using System.Text.RegularExpressions; 
using System.Windows; 
using System.Windows.Controls; 
using Outlook = Microsoft.Office.Interop.Outlook; 

namespace Data.OutlookHelper 
{ 
    public class AdxCalendar 
    { 
     public static Outlook.MAPIFolder getCallendar(Outlook.Application OutlookApp, string path) 
     { 
      Outlook.MAPIFolder calendar = null; 
      foreach (Outlook.Store store in OutlookApp.Session.Stores) 
      { 
       if (store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).FullFolderPath.Equals(path)) 
       { 
        calendar = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar); 
        break; 
       } 
       foreach (Outlook.MAPIFolder folder in store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar).Folders) 
       { 
        if (folder.FullFolderPath.Equals(path)) 
        { 
         calendar = folder; 
         break; 
        } 
       } 
       if (calendar != null) 
        break; 
      } 
      if (calendar == null) 
      { 
       return null; 
      } 
      return calendar; 
     } 
    } 
} 
Verwandte Themen