将约会添加到链接到iCloud的非默认日历中

时间:2018-11-19 11:28:09

标签: c# outlook calendar

我正在尝试将新约会添加到使用“ Windows iCloud”链接的日历中。我已经阅读了本网站上关于Outlook和Calendar的所有内容,并且使用OutlookSpy浏览了各种对象和文件夹,(感谢Dimitry为他为这个神话般的工具提供了编码社区的巨大帮助。 )。

但是,我仍然无法写入非默认日历。

基于此答案Creating an appointment to a specific calendar. VBA outlook,这是我的代码...

using Microsoft.Office.Interop.Outlook
...
Application app = new Application();
AppointmentItem appt = null;

app.ActiveExplorer().CurrentFolder = 
app.GetNamespace("MAPI").GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
Recipient recipent = app.Session.CreateRecipient("Jobs"); 

appt = app.CreateItem(OlItemType.olAppointmentItem);
appt.Subject = "Subject goes here ...";
appt.Location = "Address/Suburb/State";
appt.Body = "Job GPS: " + "-1234567 987654";
appt.Start = DateTime.Now;
appt.End = appt.Start.AddHours(2);

app.ActiveExplorer().CurrentFolder.Items.Add(appt); <--- Fails here

我不确定是要写入的日历是非Outlook日历,还是在尝试保存约会之前只是缺少某些东西。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

MAPIFolder.Items.Add仅采用字符串(消息类)或OlItemType枚举之一(例如OlItemType.olAppointmentItem = 1)

您需要使用Namespace.GetSharedDefaultFolder而不是GetDefaultFolder,后者仅用于重置OUtlook中活动选择的设备(为什么?)。