none
How to format Body of an Outlook Appointment Item using C# RRS feed

  • Question

  • I am working on a Outlook VSTO Addin, where I have the requirement to set following body properties for an Appointment: 

    a.)    Rich Text Format (RTF): As per my investigation, Outlook Object Model (OOM) provides the RTF format property for Appointment for Outlook 2010 onwards,

    but as I am also dealing with the Outlook 2007 Addin, is there a way to get  RTF format property through OOM apart from Extended MAPI way.

    b.)    HTML Format: Is there a way to get the HTML format for Appointment body through OOM for both 2007 and 2010 Addins?

    Currently, I have used Extended MAPI property (which internally converts rtf/text to html) to fetch the same as I was not able to get the same through Outlook Object Model.



    Tuesday, September 27, 2016 7:16 AM

Answers

  • Unfortunately not all MAPI properties are supported by PropertyAccessor, and looks like you've found some that aren't. 

    Instead, to work with the body of an AppointmentItem, use Inspector.WordEditor to return a Word.Document object and use Word methods to add and format text. See Chapter 17: Working with Item Bodies for more information.

    Actually, the PropertyAccessor object has a limitation for the property value. It can't write/read more than 16KB of data. You need to use Extended MAPI - the OpenProperty method allows to get an instance of the IStream interface. Or just use any third-party wrapper around that API.


    [custom.development]

    • Marked as answer by Pratik Prakash Wednesday, September 28, 2016 12:08 PM
    Tuesday, September 27, 2016 6:31 PM

All replies

  • Hello Pratik,

    a) You can use the PropertyAccessor object for that. The corresponding property of calendar items returns a PropertyAccessor object that supports creating, getting, setting, and deleting properties of the parent AppointmentItem object. For example, see Using PropertyAccessor to Set and Get properties in a meeting request .

    b) Nope. The fact is that calendar items are based on the RTF markup instead of HTML. You need to use a low-level properties for getting the job done. For that, you can use the PropertyAccessor object as was described earlier. Or just any third-party wrapper around Extended MAPI (such as Redemption, for instance).  


    [custom.development]

    Tuesday, September 27, 2016 2:24 PM
  • Hi Eugene,

    I tried using following schema through PropertyAccessor to get the properties for AppointmentItem:

    a.) HTML Body (PR_HTML):  http://schemas.microsoft.com/mapi/proptag/0x10130102

    b.) RTF (PR_RTF_COMPRESSED) : http://schemas.microsoft.com/mapi/proptag/0x10090102

    But, both of them throws following exception, while sending a new meeting request.

    base {System.SystemException}: {"The property \"http://schemas.microsoft.com/mapi/proptag/0x10130102\" does not support this operation."}

    Please do let me know, if I am using the PropertyAccessor wrong way.

    Thanks.

    Tuesday, September 27, 2016 2:45 PM
  • Unfortunately not all MAPI properties are supported by PropertyAccessor, and looks like you've found some that aren't. 

    Instead, to work with the body of an AppointmentItem, use Inspector.WordEditor to return a Word.Document object and use Word methods to add and format text. See Chapter 17: Working with Item Bodies for more information.

    Actually, the PropertyAccessor object has a limitation for the property value. It can't write/read more than 16KB of data. You need to use Extended MAPI - the OpenProperty method allows to get an instance of the IStream interface. Or just use any third-party wrapper around that API.


    [custom.development]

    • Marked as answer by Pratik Prakash Wednesday, September 28, 2016 12:08 PM
    Tuesday, September 27, 2016 6:31 PM
  • Thanks Eugene,

    I will consider both alternatives, 

    a.) Extended Mapi

    b.) Inspector.WordEditor

    and implement whichever is feasible to my requirements.

    Wednesday, September 28, 2016 12:11 PM
  • 1. Keep in mind that Extended MAPI is C++ or Delphi only

    2. Inspector.WordEditor will work great for an appointment already opened in an inspector. If you are processing a large number of items, this approach will not work.

    3. If using Redemption is an option, it exposes RtfBody and HTMLBody properties on all items in all versions of Outlook.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, September 29, 2016 4:14 PM
  • Hi Eugene,

    Now, as I am no longer using 2007 version of Outlook, I tried using AppointmentItem.RTFBody property, which works.

    But, I have a requirement to  Get or Set the binary RTF Compressed body of the Message.

    Can it be achieved using OOM?

    Thanks.

    Wednesday, October 5, 2016 3:45 PM
  • You need to use the RtfBody property. Does it not work for you?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Wednesday, October 5, 2016 6:43 PM
  • No, It doesn't give me the  binary RTF Compressed body of the Message.
    Thursday, October 6, 2016 8:31 AM
  • >>>But, I have a requirement to  Get or Set the binary RTF Compressed body of the Message.

    Can it be achieved using OOM?<<<

    According to your description, it is impossible to get or set the binary RTF Compressed body of the Message using OOM.

    Thanks for your understanding.
    Thursday, October 6, 2016 8:43 AM
  • Okay, that leaves me with the option of Extended MAPI.
    Thursday, October 6, 2016 9:35 AM
  • Why does it need to be *compressed*? If Redemption is an option, its SafeMailItem/RDOMail.Fields[] (equivalent of PropertyAccesor in OOM) does return large PT_BINARY properties as an array of byte.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, October 6, 2016 1:21 PM
  • I need compressed rtf for a condition where I have custom/unknown format of body.
    Thursday, October 6, 2016 3:08 PM
  • But what would you do with it? You cannot parse it easily. Once you uncompressed it, you will end up with the RTF body that you can easily retrieve from the RtfBody property.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, October 6, 2016 3:27 PM