Generate iCalendar feed from ASP.NET

Share

In order to feed calendar clients (like MS Outlook, Google Calendar) it is required to supply a plain text file with the ‘.ics’ extension.

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//WPCS/iManagement//..//EN
BEGIN:VEVENT
UID:7264
DTSTAMP:20090917T152000Z
SUMMARY:(16:00-17:00)iFinance pilot - kick off
CLASS:PUBLIC
DESCRIPTION:kick off meeting
CATEGORIES:IMANAGEMENT - PROJECTS
LOCATION:
STATUS:CONFIRMED
PRIORITY:1
DTSTART:20090917T160000
DTEND:20090917T170000
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

One approach is to generate the iCalendar data using the code behind of a regular .aspx page. The key part in this case is to inform the ASP processor how to handle the page: instead of displaying just text, will pass it off to the operating system. These two lines can be placed in the Page_Load event:

Response.AddHeader("content-disposition", "attachment; filename=WorkAheadFeed.ics");
Response.ContentType = "text/calendar;method=request;charset=UTF-8;component=vevent";

As an alternative – if the performance is an issue – one can use a WebHandler (.ashx file), being known that the output is not intended for a browser.
In this case will have to include the IsReusable property and place the code behind logic in the ProcessRequest() which will be invoked whenever the file is requested.

A simple feed will look like this:

   DateTime datStart = DateTime.Now.AddDays(5);
   DateTime datEnd = datStart.AddMinutes(60);
   string strLocation = "Big office";
   string strSummary = "(16:00-17:00)iFinance pilot - kick off";
   string strDescription = "kick off meeting";
 
	public static string GetFormatedDate(DateTime date)
	{
		return date.ToString("yyyyMMdd");
	}
	public static string GetFormattedTime(DateTime date, bool bUTC)
	{
		return date.ToString("HHmm") + (bUTC ? "00Z" : "00");
	}
   Response.Write("BEGIN:VCALENDAR");
   Response.Write("\nVERSION:2.0");
   Response.Write("\nPRODID:-//WPCS/iManagement//..//EN");
   Response.Write("\nBEGIN:VEVENT");
   Response.Write("\nUID:7264");
   Response.Write("\nDTSTAMP:" + GetFormatedDate(DateTime.Now) + "T" + GetFormattedTime(DateTime.Now, true));
   Response.Write("\nSUMMARY:" + strSummary);
   Response.Write("\nCLASS:PUBLIC");
   Response.Write("\nDESCRIPTION:" + strDescription);
   Response.Write("\nCATEGORIES:IMANAGEMENT - PROJECTS");
   Response.Write("\nLOCATION:" + strLocation);
   Response.Write("\nSTATUS:CONFIRMED");
   Response.Write("\nPRIORITY:1");
   Response.Write("\nDTSTART:" + GetFormatedDate(datStart) + "T" + GetFormattedTime(datStart, false)));
   Response.Write("\nDTEND:" + GetFormatedDate(datEnd) + "T" + GetFormattedTime(datEnd, false)));
   Response.Write("\nTRANSP:OPAQUE");
   Response.Write("\nEND:VEVENT");
   Response.Write("\nEND:VCALENDAR");



For complete iCalendar specification see following:

iCalendar Specification Excerpts
Internet Calendaring and Scheduling Core Object Specification

Finally, there’s another very important peculiarity of what does Cialis that brings it so high above its alternatives. It is the only med that is available in two versions – one intended for use on as-needed basis and one intended for daily use. As you might know, Viagra and Levitra only come in the latter of these two forms and should be consumed shortly before expected sexual activity to ensure best effect. Daily Cialis, in its turn, contains low doses of Tadalafil, which allows to build its concentration up in your system gradually over time and maintain it on acceptable levels, which, consequently, makes it possible for you to enjoy sex at any moment without having to time it.

By continuing to use the site, you agree to the use of cookies. More information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close