Created
January 24, 2021 05:11
-
-
Save ByronScottJones/e0fe0357469c77612f65b2ec76b7dbff to your computer and use it in GitHub Desktop.
Create iCal ics file with asp.net handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ WebHandler Language="C#" Class="MyNamespace.iCalendar" %> | |
using System; | |
using System.Web; | |
namespace MyNamespace | |
{ | |
public class iCalendar: IHttpHandler | |
{ | |
public bool IsReusable | |
{ | |
get | |
{ | |
return true; | |
} | |
} | |
string DateFormat | |
{ | |
get | |
{ | |
return "yyyyMMddTHHmmssZ"; // 20060215T092000Z | |
} | |
} | |
public void ProcessRequest(HttpContext ctx) | |
{ | |
#source http://webdevel.blogspot.com/2006/02/how-to-generate-icalendar-file-aspnetc.html | |
DateTime startDate = DateTime.Now.AddDays(5); | |
DateTime endDate = startDate.AddMinutes(35); | |
string organizer = "[email protected]"; | |
string location = "My House"; | |
string summary = "My Event"; | |
string description = "Please come to\\nMy House"; | |
ctx.Response.ContentType="text/calendar"; | |
ctx.Response.AddHeader("Content-disposition", "attachment; filename=appointment.ics"); | |
ctx.Response.Write("BEGIN:VCALENDAR"); | |
ctx.Response.Write("\nVERSION:2.0"); | |
ctx.Response.Write("\nMETHOD:PUBLISH"); | |
ctx.Response.Write("\nBEGIN:VEVENT"); | |
ctx.Response.Write("\nORGANIZER:MAILTO:" + organizer); | |
ctx.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat)); | |
ctx.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat)); | |
ctx.Response.Write("\nLOCATION:" + location); | |
ctx.Response.Write("\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@mysite.com"); | |
ctx.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat)); | |
ctx.Response.Write("\nSUMMARY:" + summary); | |
ctx.Response.Write("\nDESCRIPTION:" + description); | |
ctx.Response.Write("\nPRIORITY:5"); | |
ctx.Response.Write("\nCLASS:PUBLIC"); | |
ctx.Response.Write("\nEND:VEVENT"); | |
ctx.Response.Write("\nEND:VCALENDAR"); | |
ctx.Response.End(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment