【发布时间】:2022-01-16 02:34:37
【问题描述】:
我正在合作
- Windows 10 专业版 64 位 (21H1)
- MS Office 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;
【问题讨论】:
标签: c# outlook calendar subscription webcal