VRBO ical import from ASP.Net icalHandler
My clients wanted to import their availability calendars to VRBO so they did not have to manually sync them. I looked into several code solutions to allow my Property Management customers to export their calendars from my ASP.net property management platform to .ical format. Here is my version for icalHandler.ashx. There is no web.config changes needed.
<%@ WebHandler Language="C#" Class="icalHandler" %>
using System;
using System.Web;
public class icalHandler : IHttpHandler {
public bool IsReusable
{
get
{
return true;
}
}
string DateFormat
{
get
{
return "yyyyMMddTHHmmssZ"; // 20060215T092000Z
}
}
public void ProcessRequest(HttpContext context)
{
string listingId = context.Request.QueryString["ListingId"];
Listing listing = Listing.GetListing(new Guid(listingId));
context.Response.ContentType = "text/calendar";
context.Response.AddHeader("Content-disposition", "attachment; filename=Listing" + listing.ListingRowId + ".ics");
context.Response.Write("BEGIN:VCALENDAR");
context.Response.Write("\nVERSION:2.0");
context.Response.Write("\nMETHOD:PUBLISH");
foreach (Availability avail in listing.Availabilities)
{
DateTime startDate = avail.StartDate;
DateTime endDate = avail.EndDate;
if (startDate > DateTime.Now || endDate > DateTime.Now)
{
context.Response.Write("\nBEGIN:VEVENT");
context.Response.Write("\nORGANIZER:MAILTO:" + "info@nationalrentalpros.com");
context.Response.Write("\nDTSTART:" + startDate.ToUniversalTime().ToString(DateFormat));
context.Response.Write("\nDTEND:" + endDate.ToUniversalTime().ToString(DateFormat));
context.Response.Write("\nLOCATION:" + listing.Title);
context.Response.Write("\nUID:" + DateTime.Now.ToUniversalTime().ToString(DateFormat) + "@enkode.io");
context.Response.Write("\nDTSTAMP:" + DateTime.Now.ToUniversalTime().ToString(DateFormat));
context.Response.Write("\nSUMMARY:" + "Not Available");
context.Response.Write("\nDESCRIPTION:" + "Reserved");
context.Response.Write("\nPRIORITY:5");
context.Response.Write("\nCLASS:PUBLIC");
context.Response.Write("\nEND:VEVENT");
}
}
context.Response.Write("\nEND:VCALENDAR");
context.Response.End();
}
}
f677c7a9-be01-4ff0-8e58-3f5de0762128|0|.0|96533e0d-f2a4-44aa-b02e-d90bfc09eb89