Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding custom ItemProperties from print. Interop.Outlook

I have written an Outlook plugin that basically allows emails being received through Outlook to be linked with a website so that the email can also be view in the communications feature of the website. I store additional details within the ItemProperties of a MailItem, these details are basically things like the id of the user the email relates to within a website.

The problem I'm having is any ItemProperties I add to a MailItem are being printed when the email is printed. Does anyone know how to exclude custom ItemProperties when printing an email?

Here is the code that is creating the custom 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;
like image 518
user2367510 Avatar asked Jan 13 '23 10:01

user2367510


1 Answers

I'm working on Outlook extension and sometimes ago we had the same issue. One of our team members found a solution. You can create some method which is responsible for disable printing. You can see peace of our code below:

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);
}

Make sure that _customProperty it is your property which you created by the following code: mailItem.ItemProperties.Add(name,Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);

like image 128
Aliaksei Futryn Avatar answered Mar 28 '23 03:03

Aliaksei Futryn