【问题标题】:In Outlook C# VSTO, how can i get a reference to an appointmentItem given an EntryId, etc在 Outlook C# VSTO 中,我如何获得对给定 EntryId 等的约会项的引用
【发布时间】:2015-12-29 17:46:36
【问题描述】:

我有一个 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,什么是直接引用约会项目系列的正确代码(无需搜索所有内容并在“客户端”进行过滤

这在 Outlook vsto 中可能吗?

【问题讨论】:

  • 是否需要将EntryID存储在数据库中以备后用?或者您只是在会话期间需要它?
  • @YacoubMassad - 我正在存储 EntryId(但老实说,我看不出这会对我的问题给出不同的答案)
  • EntryID 有不同的类型,有的可以跨越不同的会话,有的只能跨越一个会话
  • 你会像这样使用它Application.GetNamespace("MAPI").GetItemFromID(entryIDForAppointment, EntryIdForStore)。商店是您正在处理的邮箱。如果邮箱里有文件夹,可以使用folder.StoreID获取店铺的入口id。

标签: c# calendar outlook vsto


【解决方案1】:

如果你想通过EntryID获取项目(MailItemFolderItemAppoinmentItem,...),你需要使用GetItemFromID(),这个方法返回一个Microsoft Outlook Item 由指定的条目 ID 标识(如果有效)。

此功能在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 属性是唯一的,除非项目不会被移动,例如,如果您使用 olMeetingAcceptedolMeetingTentative 调用 Respond() 方法,则新的约会项目不同的EntryID 被创建并被删除。

【讨论】:

    【解决方案2】:

    您想使用 NameSpace 对象的 GetItemFromID 方法(直观地说,这可以通过 Application.Session 属性访问)

    您将需要要从中检索项目的 MAPI 商店的商店 ID。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多