• Suppress user properties/ custom fields when print in Outlook


            /// <summary>
            /// Suppress User Property when Printing.
            /// http://stackoverflow.com/questions/701508/suppressing-outlook-field-printing
            /// </summary>
            /// <param name="userProperty"></param>
            public virtual void SuppressUserPropertyPrinting(OL.UserProperty userProperty)
            {
                try
                {
                    if (userProperty == null) return; // no prop found 
    
                    // Late Binding in .NET: http://support.microsoft.com/default.aspx?scid=kb;EN-US;302902
                    Type userPropertyType;
                    long dispidMember = 107;
                    long ulPropPrintable = 0x4; // removes PDO_PRINT_SAVEAS
                    string dispMemberName = String.Format("[DispID={0}]", dispidMember);
                    object[] dispParams;
    
                    userPropertyType = userProperty.GetType(); // user property type
    
                    // Call IDispatch::Invoke to get the current flags
                    object flags = userPropertyType.InvokeMember(dispMemberName, BindingFlags.GetProperty, null, userProperty, null);
    
                    // default is 45 - 
                    // PDO_IS_CUSTOM|PDO_PRINT_SAVEAS|PDO_PRINT_SAVEAS_DEF
                    // ref: http://msdn.microsoft.com/en-us/library/ee415114.aspx
                    long lFlags = long.Parse(flags.ToString());
    
                    // Remove the hidden property Printable flag
                    // change to 41 - 
                    // PDO_IS_CUSTOM|PDO_PRINT_SAVEAS_DEF 
                    // ref: http://msdn.microsoft.com/en-us/library/ee415114.aspx
                    lFlags &= ~ulPropPrintable;
    
                    // 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, null, userProperty, dispParams);
                }
                catch { } // safely ignore if property suppression doesn't work
            }

    When printing Outlook Mail Item, appointment Item etc, the custom user defined fields will display. The above method fixs this issue by change the update Flags from PDO_IS_CUSTOM|PDO_PRINT_SAVEAS|PDO_PRINT_SAVEAS_DEF to PDO_IS_CUSTOM|PDO_PRINT_SAVEAS_DEF.

  • 相关阅读:
    根据数据库表字段动态生成选择画面
    ABAP中字符串处理方法小结(二)
    如何获取汉字字符串长度
    如何强制分页-[NEW-PAGE]
    如何设置输出颜色-[FORMAT..COLOR..]
    ◆◆0如何取得字符串最后一位
    VALSE2019
    pycharm使用总结
    生活经验
    爱情存在吗-3
  • 原文地址:https://www.cnblogs.com/yoyohappy/p/4654570.html
Copyright © 2020-2023  润新知