VS.NET 2010/2012 Users Click Here   

HOMECONTACT PRODUCTS DOWNLOADS PURCHASE TESTIMONIALS FORUMS COMPANY CONTACT
Home
Products
Downloads
Purchase
Licensing
Licensing FAQ
Software Updates
Support Forums
Testimonials
Feature Requests
Guarantee
About Us
Contact Us
Hosting Companies
Privacy Policy
   
Shopping Cart


Search

iCalendar: Using HTML in the iCalendar Description Field

by Dave 28. September 2011 01:45

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

 

 



 

 

Testimonial

Just to let you know, I got everything going and tested my sample newsletter. A very nice, easy component to work with. You and your support were very responsive as well. Thanks!! "

Eric

Read more testimonials
ListNanny aspNetDNS aspNetEmail aspNetPOP3 aspNetMX aspNetMIME aspNetPING aspNetTraceRoute aspNetIMAP aspNetMHT