I recently had a request of how to use HTML formatted content in the description field of an iCalender.
Background: By default, the iCalendar specification only allows plain text to be used in the description of an iCal object. Starting with Outlook 2010, Outlook can now recognize HTML formatted content in an iCalendar. However, this is actually supported via an additional field in the iCalendar object called "X-ALT-DESC", rather than the existing field. This does 2 things:
a) Preserves background compatibility
b) Requires the developer to now set 2 description fields (the original plain text description, along with the Html description field).
Below is a code example that demonstrates creating HTML formatted content in an iCalender.
EmailMessage msg = new EmailMessage( "127.0.0.1" ); msg.From = "me@mycompany.com"; msg.To= "you@yourcompany.com"; //have a meeting tomorrow, from 10 - 11 am. DateTime startAt= DateTime.Now.AddDays( 1 ); startAt = new DateTime( startAt.Year, startAt.Month, startAt.Day, 10, 0,0 ); DateTime endAt = startAt.AddHours( 1 ); iCalendar ical = new iCalendar( "100 main", "Progress report meeting", "Weekly progress report update across departments.", startAt, endAt, iCalendarType.iCal ); ical.OptimizedFormat = OptimizedFormat.Exchange2003; //Outlook uses a custom property to display HTML called the X-ALT-DESC property string html = "<font color=#ff0000>This is some text that will be displayed in red, in newer versions of Outlook</font>"; CustomCalendarProperty htmlProp = new CustomCalendarProperty( "X-ALT-DESC", html ); htmlProp.AddParameter( "FMTTYPE", "text/html" ); ical.Event.Properties.Add( htmlProp ); //write out the iCal to a file (if we wanted to, we could also stream it to a browser ical.WriteToFile( "c:\\temp\\", iCalendarType.iCal ); //add it to the EmailMessage object, to be sent msg.AddCalendar( ical ); //as a test, just save the entire Email content to a file msg.SaveToFile( "c:\\temp\\" ); //send the email msg.Send();
As always, if anyone has any questions, feel free to content me using the Contact Us page.
Thanks,
Dave Wanta