使用C#程序读取Outlook日历约会时出错

本文关键字:约会 出错 日历 Outlook 程序 读取 使用 | 更新日期: 2023-09-27 18:24:39

一个C#窗口应用程序试图读取Outlook日历信息时出错这以前是有效的,但我认为服务器端发生了与安全相关的更改,我看不到,也不会被告知。

我正在使用Outlook 2010(v14.0.31295000)

我得到的错误是:

System.Runtime.InteropServices.COMException(0x80004005):未指定的错误(HRESULT中的异常:0x8000 4005(E_FAIL))

尝试读取约会正文时出错:

if (oAppt.Body != null)

我可以准备其他日历属性没有问题

Microsoft.Office.Interop.Outlook.RecurrencePattern recurrencePattern;
Microsoft.Office.Interop.Outlook.NameSpace oNS;
Microsoft.Office.Interop.Outlook.MAPIFolder oCalendar;
Microsoft.Office.Interop.Outlook.Items oItems;
Microsoft.Office.Interop.Outlook.AppointmentItem oAppt;
Microsoft.Office.Interop.Outlook.Application _OutlookApplication;

try
{
  _OutlookApplication = new Microsoft.Office.Interop.Outlook.Application();
  oNS = _OutlookApplication.GetNamespace("MAPI");
  // Get the Calendar folder.
  oCalendar = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
  oCalendar.Items.IncludeRecurrences = true;

  // Get the Items (Appointments) collection from the Calendar folder.
  oItems = oCalendar.Items;
  for (Int32 x = 1; x <= oItems.Count; x++)
  {
     //Need to change how we are getting the appointment
     //Apparently Outlook will return non-appointments in the calendar feed
     try
     {
        oAppt = (Microsoft.Office.Interop.Outlook.AppointmentItem)oItems[x];
        Console.WriteLine(oAppt.Subject);
      }
      catch (Exception)
      {
         continue;
      }
      if (oAppt.Body != null)
         Console.WriteLine("      Calendar Body:" + oAppt.Body.ToString());
     }
   }
   catch (Exception ex)
   {
       Console.WriteLine(ex.Message.ToString());
   }
 }

在堆栈跟踪中,我看到以下错误

 at Microsoft.Office.Interop.Outlook._AppointmentItem.get_Body()

有人能帮我解释为什么会发生这个错误吗?如果有什么我可以做的工作?

使用C#程序读取Outlook日历约会时出错

我能够与我们的一位管理员联系,发现这个特定问题是由推送到我们计算机上的组策略引起的。

这个错误并没有给你指明方向,但这就是

的问题