Thursday, 13 September 2012

Displaying HTML body in the Appointment Item VSTO

Hi,

During the development of outlook plugin, a scenario came to render the HTML page in appointment body.
Displaying an HTML body in the mail body is easy as mail item has a property called .HTMLBody but how to do with an appointment item.
I have struggled a lot to achieve this at last achieved it :-). In order to display an html content to the appointment window I have used the below process

//Place the below in using namespace list of program using Word = Microsoft.Office.Interop.Word;


private AppointmentItem _appItem; 
private MailItem _mailItem;

 private void DisplayHTMLinAppointmentItem()
{
 _appItem.Body = <B>HTML TEST</B>


 _mailItem = this.Application.CreateItem(OlItemType.olMailItem);
 _mailItem.HTMLBody = appItem.Body;
 _mailItem.Open += new ItemEvents_10_OpenEventHandler(mailItemCopy_Open);
 _mailItem.Display();


  Inspector insp = appItem.GetInspector;
  Word.Document wordDoc = insp.WordEditor as Word.Document;
  wordDoc.Windows[1].Document.Content.Paste();
}


 private void mailItemCopy_Open(ref bool Cancel)
{
            Inspector inspMail = _mailItem.GetInspector;
            Word.Document wordDocMail = inspMail.WordEditor as Word.Document;
            wordDocMail.Windows[1].Document.Content.Copy();
            Cancel = true;
}

Above code will help us to achieve the display of HTML content in appointment item.