【问题标题】:c# webcal:link in Outlook “internet calendar subscription" produce multiple instances of outlook calendars in outlook.exec# webcal:link in Outlook“internet calendar subscription”在outlook.exe中生成多个outlook日历实例
【发布时间】: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


    【解决方案1】:

    我找到了解决方法。 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;
       
           ...
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 2022-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多