c# - 在 Outlook C# VSTO 中,如何在给定 EntryId 等的情况下获取对 appointmentItem 的引用

标签 c# calendar outlook vsto

我有一个 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() 方法olMeetingAcceptedolMeetingTentative 创建一个具有不同 EntryID 的新约会项目,并删除原来的。

关于c# - 在 Outlook C# VSTO 中,如何在给定 EntryId 等的情况下获取对 appointmentItem 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34516203/

相关文章:

c# - 按未知对象类型的值进行比较

java - 在 Android 中设置当前日期

java - 从星期一开始日历

c# - 将数组从非托管 C++ 传递到 C#

c# - 使用触发器记录审计信息与存储过程

c# - ASP.NET MVC 4 View 模型

Android 日历查看颜色多个日期并禁用点击

time - Outlook 是否正确处理 .ics (ICalendar) 文件的时区?

python - 使用 python 访问 Outlook 文件夹

c# - 在 C# 中使用 WPF 显示 .msg 文件