【发布时间】:2017-05-04 12:21:43
【问题描述】:
我正在用 C# 开发一个 Office VSTO 加载项,它在 Outlook 中查找日历约会,并在其中读取/写入一些数据。
最近,其中一位客户遇到了插件问题,即他们无法读取/写入日历约会,并引发异常:
操作失败。
异常日志中没有太多信息,但我怀疑它们与 Exchange 存在同步问题。
我问过客户,他们说,他们在 Outlook 中也有一个随机弹出窗口,这有时会在与 Exchange 同步时发生意外时发生。我告诉他们“修复” Outlook 数据文件,但这并没有解决问题。
outlook 项目基本上是根据其 Outlook EntryIDs OR a Subject 来查找的(主题是唯一的,为了简单起见,我稍微翻译了代码)
...main alghorythm...
Outlook.AppointmentItem calAppointment = null;
calAppointment = SearchforCalendarMatch(EntryID, Subject); //we try to find either by EntryID or by Subject
if (calAppointment != null)
{
calAppointment.Start = StartDate;
calAppointment.End = FinishDate;
calAppointment.Body = Notes;
calAppointment.Save(); //we're changing the found calendar appointment here
}
...
public Outlook.AppointmentItem SearchforCalendarMatch(String EntryID, String Subject)
{
Outlook.NameSpace ns = null;
Outlook.MAPIFolder calendarFolder = null;
Outlook.Items calendarFolderItems = null;
Outlook.Items filteredcalendarFolderItems = null;
Outlook.AppointmentItem calAppointment = null;
Outlook.Application OutlookApp = new Outlook.Application();
outlookversion = OutlookApp.Version;
ns = OutlookApp.Session;
//Try to find the calendar appointment by the EntryID
dynamic OutlookItem = ns.GetItemFromID(t.Text28);
if (OutlookItem != null)
{
if (OutlookItem is Outlook.AppointmentItem)
{
Outlook.AppointmentItem foundItem = (Outlook.AppointmentItem)OutlookItem;
return foundItem;
}
}
//If the EntryID was missing, we try to find the calendar appointment by the Subject.
//(original code is very long, and there are multiple things here, but let's just assume that 100% sure that the subject is unique, so it will find it)
String SubjectMatch = "[Subject] = '" + Subject + "'";
filteredcalendarFolderItems = calendarFolderItems.Restrict(SubjectMatch);
for (int i = 1; i <= filteredcalendarFolderItems.Count; i++)
{
//appointment has to be one of these
calAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)filteredcalendarFolderItems[i];
if (!calAppointment.IsConflict) //conflict check here, not sure if it helps at all
{
return calAppointment; //this is not the complete code, but this is the basic idea of it.
}
}
}
有什么想法可以让应用程序识别这些失败的 Exchange 同步,并以不同的方式处理它们吗?
如果可能的话,我仍然希望在这些情况下进行同步...(更改 Outlook 中的“本地数据”,然后让 Outlook 处理此后的所有内容)
【问题讨论】:
标签: c# outlook vsto outlook-addin office-addins