c#在默认的另一个日历中添加会议请求

时间:2016-06-01 12:45:10

标签: c# outlook calendar

我想向某些人发送会议请求(列表中的邮件)。 会议无法进入默认日历。它需要位于(fullpathCalendar)"\\Methode\Calendar"

这是我到目前为止所做的:

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";

如何将约会分配到该日历?

1 个答案:

答案 0 :(得分:0)

对于想要相同的人:

        string sendText = "";
        string subject = "";
        string location = "";
        string emails = {"dsqdsqdqsd@dsqdqd.com", "sdqdqdqd@dqsd.com"};
        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();
        }

我的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;
        }
    }
}