Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To make sure I understand your question, you wish to offer a "download as .ical" button on your web application, dynamically populated with the specific calendar event data from your application?</p> <p>Think of an ical file (or more accurately, a .ics file) as just a string, but with a different Mime Type. The following describes the basics of the iCalendar format:</p> <p><a href="http://en.wikipedia.org/wiki/ICalendar" rel="nofollow">http://en.wikipedia.org/wiki/ICalendar</a></p> <p>In ASP.NET, I'd recommend creating a handler (.ashx instead of .aspx) because it is more efficient if you don't need to serve a complete web page. In the handler, replace the ProcessRequest method with something like this (credit goes to <a href="http://webdevel.blogspot.com/2006/02/how-to-generate-icalendar-file-aspnetc.html" rel="nofollow">http://webdevel.blogspot.com/2006/02/how-to-generate-icalendar-file-aspnetc.html</a>)</p> <pre><code>private string DateFormat { get { return "yyyyMMddTHHmmssZ"; } // 20060215T092000Z } public void ProcessRequest(HttpContext context) { DateTime startDate = DateTime.Now.AddDays(5); DateTime endDate = startDate.AddMinutes(35); string organizer = "foo@bar.com"; string location = "My House"; string summary = "My Event"; string description = "Please come to\\nMy House"; context.Response.ContentType="text/calendar"; context.Response.AddHeader("Content-disposition", "attachment; filename=appointment.ics"); context.Response.Write("BEGIN:VCALENDAR"); context.Response.Write("\nVERSION:2.0"); context.Response.Write("\nMETHOD:PUBLISH"); context.Response.Write("\nBEGIN:VEVENT"); context.Response.Write("\nORGANIZER:MAILTO:" + organizer); context.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat)); context.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat)); context.Response.Write("\nLOCATION:" + location); context.Response.Write("\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@mysite.com"); context.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat)); context.Response.Write("\nSUMMARY:" + summary); context.Response.Write("\nDESCRIPTION:" + description); context.Response.Write("\nPRIORITY:5"); context.Response.Write("\nCLASS:PUBLIC"); context.Response.Write("\nEND:VEVENT"); context.Response.Write("\nEND:VCALENDAR"); context.Response.End(); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload