【问题标题】:Hiding custom ItemProperties from print. Interop.Outlook从打印中隐藏自定义 ItemProperties。互操作Outlook
【发布时间】:2013-05-04 08:16:25
【问题描述】:

我编写了一个 Outlook 插件,它基本上允许通过 Outlook 接收的电子邮件与网站链接,这样电子邮件也可以在网站的通信功能中查看。我在 MailItem 的 ItemProperties 中存储了其他详细信息,这些详细信息基本上就是网站中与电子邮件相关的用户 ID。

我遇到的问题是在打印电子邮件时,我添加到 MailItem 的任何 ItemProperties 都在打印。有谁知道在打印电子邮件时如何排除自定义 ItemProperties?

这是创建自定义 ItemProperty 的代码:

// Try and access the required property.
Microsoft.Office.Interop.Outlook.ItemProperty property = mailItem.ItemProperties[name];

// Required property doesnt exist so we'll create it on the fly.
if (property == null) property = mailItem.ItemProperties.Add(name, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);

// Set the value.
property.Value = value;

【问题讨论】:

    标签: printing outlook interop mailitem


    【解决方案1】:

    我正在开发 Outlook 扩展程序,有时我们遇到了同样的问题。 我们的一位团队成员找到了解决方案。您可以创建一些负责禁用打印的方法。您可以在下面看到我们的代码的和平:

    public void DisablePrint()
    {
        long printablePropertyFlag = 0x4; // PDO_PRINT_SAVEAS
        string printablePropertyCode = "[DispID=107]";
        Type customPropertyType = _customProperty.GetType();
    
        // Get current flags.
        object rawFlags = customPropertyType.InvokeMember(printablePropertyCode , BindingFlags.GetProperty, null, _customProperty, null);
        long flags = long.Parse(rawFlags.ToString());
    
        // Remove printable flag.
        flags &= ~printablePropertyFlag;
    
        object[] newParameters = new object[] { flags };
    
        // Set current flags.
        customPropertyType.InvokeMember(printablePropertyCode, BindingFlags.SetProperty, null, _customProperty, newParameters);
    }
    

    确保 _customProperty 是您通过以下代码创建的属性:mailItem.ItemProperties.Add(name,Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);

    【讨论】:

    • 这很完美!使我的插件免于被搁置。用这个把我的头撞到墙上一个星期了。
    【解决方案2】:

    在低(扩展 MAPI)级别,每个用户属性定义都有一个标志,用于确定它是否可打印。但是,该标志不会通过 Outlook 对象模型公开。

    您可以解析用户属性 blob 并手动设置该标志(记录了用户属性 blob 格式,如果单击 IMessage 按钮,您可以在 OutlookSpy 中看到它)或者您可以使用 Redemption 及其 @ 987654323@.Printable 财产。

    以下脚本 (VB) 将为当前选定消息的所有用户属性重置可打印属性:

      set Session = CreateObject("Redemption.RDOSession")
      Session.MAPIOBJECT = Application.Session.MAPIOBJECT
      set Msg = Session.GetMessageFromID(Application.ActiveExplorer.Selection(1).EntryID)
      for each prop in Msg.UserProperties
         Debug.Print prop.Name
         prop.Printable = false
      next
      Msg.Save
    

    【讨论】:

      猜你喜欢
      • 2012-08-28
      • 2023-03-28
      • 1970-01-01
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多