码迷,mamicode.com
首页 > 其他好文 > 详细

Suppress user properties/ custom fields when print in Outlook

时间:2015-07-17 15:57:24      阅读:111      评论:0      收藏:0      [点我收藏+]

标签:

        /// <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.

Suppress user properties/ custom fields when print in Outlook

标签:

原文地址:http://www.cnblogs.com/yoyohappy/p/4654570.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!