coco
coco

Reputation: 88

Write Html code inside of Task body in Outlook

I wrote a function to pull data from SQL database and creates Outlook tasks programmatically. Some of my data is embedded in HTML tags. However, it seems like I can only put either plain text or RTF inside of task body.

Should I convert my html tags into RTF format? Or is there anyway I can write html format into task body?

Upvotes: 0

Views: 1200

Answers (1)

George Huang
George Huang

Reputation: 2523

First of all. You need to place your data inside of RTFBody property of task object. Like below:

Microsoft.Office.Interop.Outlook.TaskItem oTask = items.Add(Microsoft.Office.Interop.Outlook.OlItemType.olTaskItem) as Microsoft.Office.Interop.Outlook.TaskItem;

oTask.RTFBody = place RTF byte array here.

Then you probably need to convert your html into xaml, then from xaml to RTF format. Please refer to http://www.getcodesamples.com/src/AC5399A5/18A13477 for help.

Finally, you probably want to return the xaml code in byte array. like below:

public static byte[] ConvertHtmlToRtf(string htmlText)
{
    var xamlText = HtmlToXamlConverter.ConvertHtmlToXaml(htmlText, false);

    return System.Text.Encoding.UTF8.GetBytes(ConvertXamlToRtf(xamlText));
}

Hope this help!

Upvotes: 1

Related Questions