我有一个 outlook VSTO 插件,我可以使用以下代码检索日历约会列表:
private Items GetAppointmentsInRange(Folder folder, DateTime startTime, DateTime endTime)
{
string filter = "[Start] >= '"
+ startTime.ToString("g")
+ "' AND [End] <= '"
+ endTime.ToString("g") + "'";
Debug.WriteLine(filter);
try
{
Items calItems = folder.Items;
calItems.IncludeRecurrences = true;
calItems.Sort("[Start]", Type.Missing);
Items restrictItems = calItems.Restrict(filter);
if (restrictItems.Count > 0)
{
return restrictItems;
}
else
{
return null;
}
}
catch
{
return null;
}
}
我可以遍历此约会项目并获取我被告知的 entryId 是该系列的唯一标识符。
我现在试图弄清楚,给定一个 EntryId,什么是直接引用 appointmentItem 系列的正确代码(无需搜索所有内容并在“客户端”进行过滤
这在 outlook vsto 中可能吗?
最佳答案
如果你想通过EntryID
获取项目(MailItem
, FolderItem
, AppoinmentItem
, ...) ,您需要使用 GetItemFromID()
,此方法返回由指定条目 ID(如果有效)标识的 Microsoft Outlook 项目。
此函数在 NameSpace
对象中可用,您可以使用 Application.Session
属性或 app.GetNamespace("MAPI")
获取它调用:
var app = new Microsoft.Office.Interop.Outlook.Application();
...
var ns = app.Session; // or app.GetNamespace("MAPI");
var entryID = "<apppoinment entry id>";
var appoinment = ns.GetItemFromID(entryID) as AppointmentItem;
但建议提供文件夹的Id:
var entryID = "<apppoinment entry id>";
var storeID = "<folder store id>";
var appoinment = ns.GetItemFromID(entryID, store) as AppointmentItem;
请注意,如果您将商品移至另一家商店,EntryID
可能会发生变化。
此外,Microsoft 建议解决方案不应依赖于唯一的 EntryID
属性,除非项目不会被移动,例如,如果您调用 Respond()
方法olMeetingAccepted
或 olMeetingTentative
创建一个具有不同 EntryID
的新约会项目,并删除原来的。
关于c# - 在 Outlook C# VSTO 中,如何在给定 EntryId 等的情况下获取对 appointmentItem 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34516203/