我正在为我的公司开发一个与Outlook日历同步的日历。
自动取款机我可以:
唯一的问题是在我的约会更新/删除时更新/删除Outlook约会。
我有相应约会的GlobalAppointmentID,但我似乎无法在ID上搜索。
我试过:
using Microsoft.Office.Interop;
private void GetAppointment(string myGlobalAppointmentID)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace mapiNamespace = oApp.GetNamespace("MAPI");
Outlook.MAPIFolder calendarFolder = mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items outlookCalendarItems = calendarFolder.Items;
Outlook.AppointmentItem appointmentItem = (Outlook.AppointmentItem)outlookCalendarItems.Find("[GlobalAppointmentID] = '{0}'", myGlobalAppointmentID));
//update or delete appointmentItem here (which I know how to do)
}我一直得到“条件是无效”的例外。显然,Outlook不允许搜索二进制属性(如GlobalAppointmentID)。
我使用相同的outlookCalendarItems.Find()和calendarFolder.Items.Restrict(),在其他情况下没有问题。
我试着用“救赎”( Redemption ),但也没能让它起作用。有人有经验或建议吗?
发布于 2021-12-13 09:15:20
在深入研究之后,我做了什么:我添加了一个文本UserProperty,我在其中放置了GlobalAppointmentID("GAID")。你可以在上面过滤。而且它似乎起了作用。
private void AddGAIDIfNeeded(Outlook.AppointmentItem app)
{
bool GAIDexists = false;
if (app.UserProperties.Count != 0)
{
foreach (UserProperty item in app.UserProperties)
{
if (item.Name == "GAID")
{
GAIDexists = true;
break;
}
}
}
if (GAIDexists == false)
{
app.UserProperties.Add("GAID", Outlook.OlUserPropertyType.olText);
app.UserProperties["GAID"].Value = app.GlobalAppointmentID;
app.Save();
}
}为了找到一个特定的AppointmentItem:
private void DeleteOutlookAppointmentByGAID(string globalAppointmentID)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace mapiNamespace = oApp.GetNamespace("MAPI");
Outlook.MAPIFolder calendarFolder = mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
Outlook.Items outlookCalendarItems = calendarFolder.Items;
try
{
Outlook.AppointmentItem appointmentItem = null;
appointmentItem = outlookCalendarItems.Find(String.Format("[GAID] = '{0}'", globalAppointmentID));
if (appointmentItem != null)
{
appointmentItem.Delete();
}
}
catch (Exception ex)
{
classExecptionLogging.LogErrorToFolder(ex);
}
}发布于 2021-12-10 15:37:28
是的,OOM不允许您搜索二进制属性(以及收件人或附件),但是赎罪 (我是它的作者)应该可以工作。下面的脚本(VBA)对我来说运行得很好:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set Folder = Session.GetDefaultFolder(olFolderCalendar)
set appt = Folder.Items.Find("GlobalAppointmentID = '040000008200E00074C5B7101A82E00800000000D0FECEE58FEAD70100000000000000001000000041C887A3FA12694F8A0402FEFFAD0BBB'")
MsgBox appt.Subject发布于 2021-12-10 15:38:22
Outlook对象模型不支持使用Items.Find/Items.FindNext/Items.Restrict.搜索二进制属性(如GlobalAppointmentId (任何其他PT_BINARY属性))
唯一的解决办法是循环遍历Calendar文件夹中的所有项(这是效率低下的),或者使用扩展的MAPI进行搜索(或者使用第三方包装,比如Redemption )。
https://stackoverflow.com/questions/70306182
复制相似问题