0

我正在与

  • 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;
4

1 回答 1

0

我找到了解决方法。c# 语句“OpenSharedFolder(webCalString)”在 MS Outlook 中创建新的“其他日历”。我没有找到使用 c# 访问这些私人日历的权限。但是,以下过程允许读取 Internet 网络日历:

  1. 在 MS Outlook 中订阅 Internet 网络日历。此日历在 MS Outlook 中显示为“共享日历”
  2. 以下代码获取 CalendarFolderWeb.Folders 中的所有共享子文件夹:
CalendarFolderWeb = mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

// Go through all subfolders

foreach (Outlook.MAPIFolder **subFolder** in CalendarFolderWeb.Folders) {

   outlookCalendarItemsWeb = subFolder.Items;

   outlookCalendarItemsWeb.IncludeRecurrences = true;

   ...

// now go thru the individual calendar items

   foreach (Outlook.AppointmentItem item in outlookCalendarItemsWeb) {
       string content = item.Subject;
   
       ...
   }
}
于 2022-01-15T16:45:41.400 回答