Thursday, March 31, 2011

Outlook AppointmentItem - How do I programmatically add RTF to its Body?

I would like to set the Body of an AppointmentItem to a string of RTF that contains an embedded image. Setting Microsoft.Office.Interop.Outlook.AppointmentItem.Body results in the RTF appearing as-is in the appointment.

I have tried using Redemption which wraps the appointment and exposes an RTFBody property, but the RTF formatting (including the image) is lost.

In this example (which doesn't have an embedded image) the RTF appears in the document as-is. Has anyone managed to do this?

var appointment = (AppointmentItem)app.CreateItem(OlItemType.olAppointmentItem);
appointment.Subject = "test subject";
appointment.Start = DateTime.Now;
appointment.End = DateTime.Now.AddHours(1);
appointment.Body = @"{\rtf1\ansi\deff0{\fonttbl{\f0 Arial;}}{\colortbl ;\red0\green0\blue255;}\pard\cf1\f0\fs24 Test}";
appointment.Save();
From stackoverflow
  • Start setting BodyFormat property before setting the Body.

    "http://msdn.microsoft.com/en-us/library/aa211430(office.11).aspx"

    Stuart Harris : The BodyFormat property is not available on AppointmentItem. They are different to mailItems and don't support HTML (only text + RTF). Thanks for your help though.

0 comments:

Post a Comment