加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 抑制Outlook字段打印

发布时间:2020-12-15 19:30:19 所属栏目:百科 来源:网络整理
导读:我们为Outlook编写了一个附加组件,用于将电子邮件存入我们的CRM系统.在此过程中,它将Outlook消息ID作为UserField保存在消息本身上. 例如. currentUserProperty = Constants.APPLICATION_NAME + "EntryID";mailItem.UserProperties.Add(currentUserProperty,M
我们为Outlook编写了一个附加组件,用于将电子邮件存入我们的CRM系统.在此过程中,它将Outlook消息ID作为UserField保存在消息本身上.

例如.

currentUserProperty = Constants.APPLICATION_NAME + "EntryID";
mailItem.UserProperties.Add(currentUserProperty,Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText,Missing.Value,Missing.Value).Value = entryId;

不幸的是,这是一个HUUUGGEE号码,很像:

“00000000D502D779150E2F4580B1AADDF04ECDA6070097EF5A1237597748A4B4F9BFF540020800000006E9E4000068BB5B6DFC36924FAEC709A17D056583000002DE0E350000”

问题是,当用户打印消息时,Outlook坚持要包含此字段(在From / To下面)并且因为它没有空格,所以无法包装ID并压缩A4页面直到它可以水平放置.这会产生极小的电子邮件打印输出.

有什么方法可以纠正这个吗?我曾想过用一个空格分隔的覆盖字段OriginalEntryID(导致问题的那个),但是我从COM层得到一个异常.我的下一步是尝试抑制Outlook上此和其他用户定义字段的输出静止.

有谁知道如何实现这一目标?

解决方法

您必须使用.NET Reflection来解决此问题(根据Microsoft支持人员的建议).希望这将在未来版本的VSTO SDK中得到修复.

取消Outlook用户字段打印

static void SuppressUserPropertyPrinting(Outlook.MailItem message)
{
    try
    {   // Late Binding in .NET: https://support.microsoft.com/en-us/kb/302902
        Type userPropertyType;
        long dispidMember = 107;
        long ulPropPrintable = 0x4; // removes PDO_PRINT_SAVEAS
        string dispMemberName = String.Format("[DispID={0}]",dispidMember);
        object[] dispParams;

        if (message.UserProperties.Count == 0) return; // no props found (exit)

        // marks all user properties as suppressed
        foreach (Outlook.UserProperty userProperty in message.UserProperties.Cast<Outlook.UserProperty>())
        {
            if (userProperty == null) continue; // no prop found (go to next)
            userPropertyType = userProperty.GetType(); // user property type

            // Call IDispatch::Invoke to get the current flags
            object flags = userPropertyType.InvokeMember(dispMemberName,BindingFlags.GetProperty,null,userProperty,null);
            long lFlags = long.Parse(flags.ToString()); // default is 45 - PDO_IS_CUSTOM|PDO_PRINT_SAVEAS|PDO_PRINT_SAVEAS_DEF (ref: http://msdn.microsoft.com/en-us/library/ee415114.aspx)

            // Remove the hidden property Printable flag
            lFlags &= ~ulPropPrintable; // change to 41 - // PDO_IS_CUSTOM|PDO_PRINT_SAVEAS_DEF (ref: http://msdn.microsoft.com/en-us/library/ee415114.aspx)

            // Place the new flags property into an argument array
            dispParams = new object[] { lFlags };

            // Call IDispatch::Invoke to set the current flags
            userPropertyType.InvokeMember(dispMemberName,BindingFlags.SetProperty,dispParams);
        }
    }
    catch { } // safely ignore if property suppression doesn't work
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读