zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    day15—jQuery UI之widgets插件
    day14—jQuery UI 之dialog部件
    day13—CSS之导航栏
    day12—jQuery ui引入及初体验
    day11—前端学习之我不想看书
    struts2的action方法匹配以及通配符的使用
    Java中的static
    ActiveMQ的简单使用
    MS DOS 常用命令整理
    IntelliJ IDEA 中 Ctrl+Alt+Left/Right 失效
  • 原文地址:https://www.cnblogs.com/yoyohappy/p/4654570.html
Copyright © 2011-2022 走看看