我正在与
- Windows 10 专业版 64 位 (21H1)
- 微软办公软件 2013
- VS 2019 (v16.11.3)
我正在尝试使用 C# 阅读订阅的 webcal - 日历。每次OpenSharedFolder(webCalString)
执行时,该过程都会从一个小窗口开始,显示“正在连接到 Web 服务器……”,然后打开 Microsoft Outlook.exe 用户界面,并在“我的日历”下创建此日历的新实例。如果在启动我的 C# 程序之前已打开 Outlook,则不会出现此问题。
我的代码很简单,它使用Microsoft.Office.Interop.Outlook
. 我添加了一个参考MS Office 15.0 Object library 2.7 (15.0.5363.1000)
:
using System;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
…
string webCalString = “webcal://koenigstein.mein-abfallkalender.de/ical.ics?sid=26035&cd=inline&ft=noalarm&fp=next_1000&wids=657,919,661,658,656,659,660,662,663&uid=46006&pwid=3ade10b890&cid=94”;
// initially set to NULL
Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.Folder CalendarFolderAbo = null;
oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace(“MAPI”); ;
// these 2 lines are necessary, otherwise OpenSharedFolder(“webcal”) does not work (why???)
Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
**// the following line opens outlook.exe, shows the User Interface of MS- Outlook, and always produces a new instance of this subscribed calendar under “My Calendars”**
CalendarFolderAbo = mapiNamespace.OpenSharedFolder(webCalString) as Outlook.Folder;